Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
A coroutine essentially is a throttling mechanism: it takes in a tick-event or tick count and executes its action when the time (number of ticks) passed between the last call and the current one is larger than the time the action reported the next call needed to wait. More...
#include <cs_Coroutine.h>
Public Types | |
typedef std::function< uint32_t(void)> | Action |
Public Member Functions | |
Coroutine ()=default | |
Coroutine (Action a) | |
void | onTick (uint32_t currentTickCount) |
To be called on tick event. More... | |
bool | handleEvent (event_t &evt) |
Convenience function replacing onTick(). More... | |
uint32_t | getNextCallTickCount () const |
Static Public Member Functions | |
static uint32_t | delayMs (uint32_t ms) |
static uint32_t | delayS (uint32_t s) |
Public Attributes | |
Action | action |
Private Attributes | |
uint32_t | nextCallTickcount = 0 |
A coroutine essentially is a throttling mechanism: it takes in a tick-event or tick count and executes its action when the time (number of ticks) passed between the last call and the current one is larger than the time the action reported the next call needed to wait.
Example: uint32_t sayHi() { LOGd("hi"); return 42; } Coroutine hiSayer (sayHi);
for (int i = 0; ; i++){ hiSayer.onTick(i); }
This will log "hi" only one in 42 calls.
Note that the return value of sayHi determines the delay, so that a coroutine can dynamically determine if it needs to be called more often or not.
typedef std::function<uint32_t(void)> Coroutine::Action |
|
default |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inline |
|
inline |
Convenience function replacing onTick().
To be called on event.
|
inline |
To be called on tick event.
Action Coroutine::action |
|
private |