1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-07 06:01:35 +03:00

Add mechanism for posting functions to the main loop (#2082)

* Add mechanism for posting functions to the main loop (#1064)

* Fix indentation, add note that API is not stable
This commit is contained in:
Ivan Grokhotkov
2016-06-08 11:22:48 +08:00
parent 6bb8e1145b
commit 5eb6a7f449
4 changed files with 203 additions and 0 deletions

27
cores/esp8266/Schedule.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef ESP_SCHEDULE_H
#define ESP_SCHEDULE_H
#include <functional>
#define SCHEDULED_FN_MAX_COUNT 32
#define SCHEDULED_FN_INITIAL_COUNT 4
// Warning
// This API is not considered stable.
// Function signatures will change.
// You have been warned.
// Run given function next time `loop` function returns,
// or `run_scheduled_functions` is called.
// Use std::bind to pass arguments to a function, or call a class member function.
// 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.
bool schedule_function(std::function<void(void)> fn);
// Run all scheduled functions.
// Use this function if your are not using `loop`, or `loop` does not return
// on a regular basis.
void run_scheduled_functions();
#endif //ESP_SCHEDULE_H