forked from Darredevil/D-Fibers
-
Notifications
You must be signed in to change notification settings - Fork 3
/
event.d
43 lines (37 loc) · 827 Bytes
/
event.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env dub
/ dub.json:
{
"name" : "event",
"dependencies": {
"photon": { "path" : ".." }
}
}
/
module examples.event;
import core.thread;
import std.stdio;
import photon;
shared Event ev1, ev2;
enum iterations = 2;
void firstJob() {
writeln("Wait for the second to trigger the event");
ev1.waitAndReset();
writeln("First triggers event for the second");
ev2.trigger();
writeln("First is done");
}
void secondJob() {
writeln("Second triggers event for the first");
ev1.trigger();
writeln("Triggered event for the first, now waiting for trigger back");
ev2.waitAndReset();
writeln("Second is done");
}
void main() {
ev1 = event(false);
ev2 = event(false);
startloop();
go(&firstJob);
go(&secondJob);
runFibers();
}