aboutsummaryrefslogtreecommitdiff
path: root/tests/actor/accept/generic_declaration.zc
blob: a5e5e77479b5330ed3e245bee47f0d77c411d559 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace;
include rt, actor;
typecheck on;
actor Counter<T> { T total; T handle(T input) { this.total += input; return this.total; } }
fn main() {
 Counter<int>* a = rt.new(Counter<int>), b = rt.new(Counter<int>);
 Counter<float>* c = rt.new(Counter<float>); int left = 0, right = 0, floating = 0;
 a.spawn(); b.spawn(); c.spawn();
 a.recv(fn(int n) { left = n; return 0; }); b.recv(fn(int n) { right = n; return 0; });
 c.recv(fn(float n) { floating = n; return 0; });
 a.send(2); a.send(3); b.send(7); c.send(1.5); c.send(2.5);
 a.await(); b.await(); c.await();
 rt.put_n(left); rt.put_c(' '); rt.put_n(right); rt.put_c(' '); rt.put_n(floating); rt.put_c(' '); rt.put_n(a.total); rt.put_c(10);
 a.close(); b.close(); c.close(); return 0;
}