-
Notifications
You must be signed in to change notification settings - Fork 13.3k
scheduled functions: fixes #6137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@d-a-v Please also make changes to Schedule.h:
except, that
|
Is that only for the schedule_functions_us or also for the current schedule_functions ? |
@hreintke @d-a-v Opinions on use cases vary widely, it seems. I personally tend to side with @hreintke - in fact, I am currently trying to concoct a test case and it just keeps crashing badly - I am not sure if this is exactly because yield() now causes an internal recursion :-( Hoping it's something else... |
@d-a-v The repeating doesn't work, the 2nd arg to schedule_function_us only specifies the initial delay, after that, the function is continually run without delays. |
The following runs smoothly (polledTimeout self-resets)
Opened for review |
@d-av : What I do see that the schedule_function has an essential changed functionality because of also running them at yield(); In this
and :
The function is called three times per loop() instead of the current once |
@hreintke #6039 was merged about 2 days ago. This commit just brings (final?) fixes.
Does this break anything with your current use-case ? |
The only differences since #6039 are:
edit: The mDNS loop could be called that way |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@d-a-v This below has somehow gotten lost between your fixes?
About polledTimeout, you're right, my handling of requeueing was conflicting, I've fixed this.
@d-a-v
The delay (100) in the scheduled function is not done, returns immediate.
|
@hreintke I said One immediate solution would be to replace
Another solution is an API change to allow calling non-recurrent function only on next A third solution is modifying I must ask for my curiosity why it is necessary to call |
@d-a-v : Although I can't find it now/remember which , some library called delay in a specific function, The nasty issue is then that a very common and know function like delay() doesn't work as expected. Because of the external libs, using the polledTimeout would require local patches. If the wish list for functionality is still open 😄 I would like to have an option to remove a function from the list. Something like we can do in CallBackList, return a shared_ptr which can be reset or can go out of scope. (When I was working on CallBacklist, I had the idea to have the scheduled_functions just to be a specific case of callbacks) Modifying delay() to allocate structure and allow reentrancy is probably quite challenging. |
It is. I need the functionality in yield and I found it useful to put the former one in yield too (the api was still marked "unstable" or so) I think we agree We can revert to the old behaviour: scheduled functions only called at To make it better can add a parameter with default value to keep previous behavior:
It would be up to the user to ensure |
// Note: there is no mechanism for cancelling scheduled functions. | ||
// Keep that in mind when binding functions to objects which may have short lifetime. | ||
// Returns false if the number of scheduled functions exceeds SCHEDULED_FN_MAX_COUNT. | ||
// * Run the lambda only once next time | ||
//bool schedule_function(std::function<void(void)>&& fn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// it returns false. | ||
// * Note that it may be more than <repeat_us> microseconds between calls if | ||
// `yield` is not called frequently, and therefore should not be used for | ||
// timing critical operations. | ||
//bool schedule_function_us(std::function<bool(void)>&& fn, uint32_t repeat_us); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.