|
3 | 3 |
|
4 | 4 | #include <functional>
|
5 | 5 |
|
6 |
| -#define SCHEDULED_FN_MAX_COUNT 32 |
| 6 | +// This API is stabilizing |
| 7 | +// Function signatures may change, internal queue will remain FIFO. |
| 8 | +// |
| 9 | +// * Add the given lambda to a fifo list of lambdas, which is run when |
| 10 | +// - `loop` function returns, |
| 11 | +// - or `yield` is called, |
| 12 | +// - or `run_scheduled_functions` is called. |
| 13 | +// |
| 14 | +// * Use lambdas to pass arguments to a function, or call a class/static |
| 15 | +// member function. |
| 16 | +// |
| 17 | +// * Please ensure variables or instances used from inside lambda will exist |
| 18 | +// when lambda is later called |
| 19 | +// |
| 20 | +// * There is no mechanism for cancelling scheduled functions. |
| 21 | +// |
| 22 | +// * `yield` can be called from inside lambdas |
| 23 | +// |
| 24 | +// * Returns false if the number of scheduled functions exceeds |
| 25 | +// SCHEDULED_FN_MAX_COUNT. |
7 | 26 |
|
8 |
| -// This API was not considered stable but is now stabilizing. |
9 |
| -// Function signatures may change, queue must stay FIFO. |
10 |
| -// You have been warned. |
| 27 | +#define SCHEDULED_FN_MAX_COUNT 32 |
11 | 28 |
|
12 |
| -// Run given function ONCE next time `loop` function returns, |
13 |
| -// or `yield` is called, |
14 |
| -// or `run_scheduled_functions` is called. |
15 |
| -// Use std::bind to pass arguments to a function, or call a class member function. |
16 |
| -// Note: there is no mechanism for cancelling scheduled functions. |
17 |
| -// Keep that in mind when binding functions to objects which may have short lifetime. |
18 |
| -// Returns false if the number of scheduled functions exceeds SCHEDULED_FN_MAX_COUNT. |
| 29 | +// * Run the lambda only once next time |
19 | 30 | //bool schedule_function(std::function<void(void)>&& fn);
|
20 | 31 | bool schedule_function(const std::function<void(void)>& fn);
|
21 | 32 |
|
22 |
| -// Run given function periodically about every <repeat_us> microseconds until it returns false. |
23 |
| -// Note that it may be more than <repeat_us> microseconds between calls if `yield` is not called |
24 |
| -// frequently, and therefore should not be used for timing critical operations. |
| 33 | +// * Run the lambda periodically about every <repeat_us> microseconds until |
| 34 | +// it returns false. |
| 35 | +// * Note that it may be more than <repeat_us> microseconds between calls if |
| 36 | +// `yield` is not called frequently, and therefore should not be used for |
| 37 | +// timing critical operations. |
25 | 38 | //bool schedule_function_us(std::function<bool(void)>&& fn, uint32_t repeat_us);
|
26 | 39 | bool schedule_function_us(const std::function<bool(void)>& fn, uint32_t repeat_us);
|
27 | 40 |
|
|
0 commit comments