diff options
Diffstat (limited to 'tests/actor/accept/state.zc')
| -rw-r--r-- | tests/actor/accept/state.zc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/actor/accept/state.zc b/tests/actor/accept/state.zc new file mode 100644 index 0000000..e53a12a --- /dev/null +++ b/tests/actor/accept/state.zc @@ -0,0 +1,15 @@ +namespace; +include rt, actor; +typecheck on; +actor Counter { int value; fn add(int n) { this.value += n; return this.value; } int handle(int n) { return this.add(n); } } +fn main() { + actor.Actor<int, int>* a = rt.new(actor.Actor<int, int>), b = rt.new(actor.Actor<int, int>); + let state = 0, aresult = 0, bresult = 0; + a.spawn(fn(int n) { state += n; return state; }); + b.spawn(fn(int n) { state += n; return state; }); + a.recv(fn(int n) { aresult = n; return 0; }); b.recv(fn(int n) { bresult = n; return 0; }); + a.send(2); a.send(3); b.send(7); a.await(); b.await(); + rt.put_n(state); rt.put_c(' '); rt.put_n(aresult); rt.put_c(' '); rt.put_n(bresult); rt.put_c(10); + Counter c; c.value = 0; c.add(4); rt.put_n(c.value); rt.put_c(10); + a.close(); b.close(); return 0; +} |
