-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoport_test.d
57 lines (49 loc) · 905 Bytes
/
goport_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import std.stdio;
import std.datetime;
import channel;
import goroutine;
import time;
import sync;
void main() {
auto ticker = Ticker(dur!"msecs"(10));
go!({for (int i=0; i<10; i++) {
writeln("tick ", ticker._);
}});
writeln("=-=========-=");
auto ch = makeChan!int(1);
go!({
foreach (i; 22..444) {
ch._ = i;
}
ch.close();
writeln("done");
});
foreach (i; 0..400) {
writeln("pop: ", ch._);
}
writeln("=-=========-=");
writeln(Clock.currTime);
After(dur!"msecs"(1000));
writeln(Clock.currTime);
writeln("done 1 secs");
while (!ch.empty) {
writeln(ch._);
}
auto timeoutch = After(dur!"msecs"(100));
while (true) {
switch (select(ch, timeoutch)) {
case 0:
writeln("zero", ch._);
break;
case 1:
writeln("time is up", timeoutch._);
break;
case -1: // all closed
goto outahere;
default:
sleep();
}
}
outahere:
return;
}