Skip to content

Commit 479f2cc

Browse files
committed
Fix callAt bug
1 parent 45958c8 commit 479f2cc

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

dub.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"description": "Asynchonous IO library for D",
44
"license": "Boost 1.0",
55
"copyright": "Copyright © 2014-2015 Dragoş Carp",
6-
"authors": ["Dragoş Carp"],
6+
"authors": [
7+
"Dragoş Carp"
8+
],
79
"targetType": "library",
810
"targetPath": "build",
911
"workingDirectory": "build",
@@ -13,6 +15,13 @@
1315
"configurations": [
1416
{
1517
"name": "library"
18+
},
19+
{
20+
"name": "unittest",
21+
"targetType": "executable",
22+
"sourcePaths": ["test"],
23+
"buildOptions": ["debugInfoC", "unittests"],
24+
"dflags": ["-main"]
1625
}
1726
]
1827
}

src/asynchronous/events.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ abstract class EventLoop
369369
*
370370
* This method’s behavior is the same as $(D_PSYMBOL callLater()).
371371
*/
372-
final auto callAt(Callback, Args...)(SysTime when, Dg dg, Args args)
372+
final auto callAt(Dg, Args...)(SysTime when, Dg dg, Args args)
373373
{
374374
auto callback = new Callback!(Dg, Args)(this, dg, args);
375375

test/events.d

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import asynchronous;
2+
3+
unittest
4+
{
5+
auto loop = getEventLoop;
6+
bool fooCalled = false;
7+
8+
void foo()
9+
{
10+
fooCalled = true;
11+
loop.stop;
12+
}
13+
14+
loop.callSoon(&foo);
15+
loop.runForever;
16+
17+
assert(fooCalled);
18+
}
19+
20+
unittest
21+
{
22+
import std.datetime : msecs;
23+
24+
auto loop = getEventLoop;
25+
auto t1 = loop.time;
26+
bool fooCalled = false;
27+
28+
void foo()
29+
{
30+
fooCalled = true;
31+
loop.stop;
32+
}
33+
34+
loop.callLater(5.msecs, &foo);
35+
loop.runForever;
36+
37+
assert(fooCalled);
38+
39+
auto t2 = loop.time;
40+
41+
assert(t2 - t1 >= 5.msecs);
42+
}
43+
44+
unittest
45+
{
46+
import std.datetime : msecs, Clock;
47+
48+
auto loop = getEventLoop;
49+
auto t1 = loop.time;
50+
bool fooCalled = false;
51+
52+
void foo()
53+
{
54+
fooCalled = true;
55+
loop.stop;
56+
}
57+
58+
loop.callAt(t1 + 5.msecs, &foo);
59+
loop.runForever;
60+
61+
assert(fooCalled);
62+
63+
auto t2 = loop.time;
64+
65+
assert(t2 - t1 >= 5.msecs);
66+
}

0 commit comments

Comments
 (0)