mbed_example
/
events_ex_3
mbed events example
Diff: main.cpp
- Revision:
- 0:fca134a32b61
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 07 16:01:39 2017 +0000 @@ -0,0 +1,29 @@ +#include "mbed_events.h" +#include <stdio.h> + +/** +Event queues easily align with module boundaries, where internal state can be +implicitly synchronized through event dispatch. Multiple modules can use +independent event queues, but still be composed through the EventQueue::chain function. +**/ + +int main() { + // Create some event queues with pending events + EventQueue a; + a.call(printf, "hello from a!\n"); + + EventQueue b; + b.call(printf, "hello from b!\n"); + + EventQueue c; + c.call(printf, "hello from c!\n"); + + // Chain c and b onto a's event queue. Both c and b will be dispatched + // in the context of a's dispatch function. + c.chain(&a); + b.chain(&a); + + // Dispatching a will in turn dispatch b and c, printing hello from + // all three queues + a.dispatch(); +} \ No newline at end of file