mbed events example

Files at this revision

API Documentation at this revision

Comitter:
sarahmarshy
Date:
Thu Sep 07 16:01:39 2017 +0000
Commit message:
Initial commit;

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Thu Sep 07 16:01:39 2017 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Sep 07 16:01:39 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#98ba8acb83cfc65f30a8a0771a27c71443ab093a