aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/actor.zc
blob: 5256aca263af0b5e6e79f40329748d81aa97abd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
namespace;
include rt, actor;
typecheck on;
int add_two(int n) { return n + 2; }
fn main() {
 actor.Actor<int,int>* a = rt.new(actor.Actor<int,int>);
 let total = 0;
 a.spawn(add_two); a.recv(fn(int value) { total += value; return 0; });
 a.send(2); a.send(3); a.await(); rt.put_n(total); rt.put_c(' ');
 a.send(1); a.await(); rt.put_n(total); rt.put_c(' ');
 a.close(); rt.put_n(a.send(4)); rt.put_c(10); return 0;
}