import core.atomic; // write a test of runActor static final synchronized class SharedCounter { this() {} private int count; void inc() { atomicOp!"+="(count, 1); } int value() { return count; } } static struct TestActor { this(shared(SharedCounter) counter) { this.counter = counter; } @ThreadEvent void inc() { counter.inc(); } bool isEnd() { return counter.value > 2; } shared(SharedCounter) counter; } auto scnt = new shared SharedCounter(); auto con = runActor!TestActor(scnt); con.inc(); Thread.sleep(dur!"msecs"(100)); assert(scnt.value == 1); con.inc(); Thread.sleep(dur!"msecs"(100)); assert(scnt.value == 2); con.inc(); Thread.sleep(dur!"msecs"(100)); assert(scnt.value == 3); con.inc(); Thread.sleep(dur!"msecs"(100)); assert(scnt.value == 3);
アクターAを別スレッドで起動し,ActorConnectionを返します.