runActor

アクターAを別スレッドで起動し,ActorConnectionを返します.

runActor
(
A
Params...
)
(
Params params
)

Examples

1 import core.atomic;
2 // write a test of runActor
3 
4 static
5 final synchronized class SharedCounter
6 {
7     this() {}
8 
9     private int count;
10 
11     void inc() { atomicOp!"+="(count, 1); }
12     int value() { return count; }
13 }
14 
15 
16 static struct TestActor
17 {
18     this(shared(SharedCounter) counter) { this.counter = counter; }
19 
20     @ThreadEvent void inc() { counter.inc(); }
21     bool isEnd() { return counter.value > 2; }
22 
23     shared(SharedCounter) counter;
24 }
25 
26 auto scnt = new shared SharedCounter();
27 auto con = runActor!TestActor(scnt);
28 con.inc();
29 Thread.sleep(dur!"msecs"(100));
30 assert(scnt.value == 1);
31 
32 con.inc();
33 Thread.sleep(dur!"msecs"(100));
34 assert(scnt.value == 2);
35 
36 con.inc();
37 Thread.sleep(dur!"msecs"(100));
38 assert(scnt.value == 3);
39 
40 con.inc();
41 Thread.sleep(dur!"msecs"(100));
42 assert(scnt.value == 3);

Meta