2016-10-19 20:00:32 +00:00
|
|
|
/++ dub.sdl:
|
|
|
|
name "test"
|
|
|
|
dependency "eventcore" path=".."
|
|
|
|
+/
|
|
|
|
module test;
|
|
|
|
|
|
|
|
import eventcore.core;
|
|
|
|
import std.datetime : Clock, SysTime, UTC;
|
|
|
|
import std.stdio : writefln;
|
|
|
|
import core.time : Duration, msecs;
|
|
|
|
|
|
|
|
SysTime s_startTime;
|
|
|
|
int s_cnt = 0;
|
|
|
|
bool s_done;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
s_startTime = Clock.currTime(UTC());
|
|
|
|
|
|
|
|
auto tm = eventDriver.timers.create();
|
|
|
|
eventDriver.timers.wait(tm, (tm) nothrow @safe {
|
2017-12-16 17:53:58 +00:00
|
|
|
Duration dur;
|
|
|
|
|
|
|
|
{
|
|
|
|
scope (failure) assert(false);
|
|
|
|
dur = Clock.currTime(UTC()) - s_startTime;
|
|
|
|
}
|
2016-10-19 20:00:32 +00:00
|
|
|
|
2017-12-17 10:23:35 +00:00
|
|
|
try {
|
2017-12-17 19:34:52 +00:00
|
|
|
assert(dur > 1200.msecs, (dur - 1200.msecs).toString());
|
|
|
|
assert(dur < 1300.msecs, (dur - 1200.msecs).toString());
|
2017-12-17 10:23:35 +00:00
|
|
|
} catch (Exception e) assert(false, e.msg);
|
2017-12-16 17:53:58 +00:00
|
|
|
|
|
|
|
s_startTime += dur;
|
2016-10-19 20:00:32 +00:00
|
|
|
|
2017-12-17 19:34:52 +00:00
|
|
|
eventDriver.timers.set(tm, 300.msecs, 300.msecs);
|
2016-10-19 20:00:32 +00:00
|
|
|
|
|
|
|
void secondTier(TimerID timer) nothrow @safe {
|
2016-12-19 21:21:51 +00:00
|
|
|
try {
|
|
|
|
auto dur = Clock.currTime(UTC()) - s_startTime;
|
|
|
|
s_cnt++;
|
2017-12-17 19:34:52 +00:00
|
|
|
assert(dur > 300.msecs * s_cnt, (dur - 300.msecs * s_cnt).toString());
|
|
|
|
assert(dur < 300.msecs * s_cnt + 100.msecs, (dur - 300.msecs * s_cnt).toString());
|
2017-06-10 08:28:16 +00:00
|
|
|
assert(s_cnt <= 3);
|
2016-12-19 21:21:51 +00:00
|
|
|
|
|
|
|
if (s_cnt == 3) {
|
|
|
|
s_done = true;
|
2017-06-10 08:28:16 +00:00
|
|
|
eventDriver.timers.stop(timer);
|
2016-12-19 21:21:51 +00:00
|
|
|
} else eventDriver.timers.wait(tm, &secondTier);
|
|
|
|
} catch (Exception e) {
|
|
|
|
assert(false, e.msg);
|
|
|
|
}
|
2016-10-19 20:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eventDriver.timers.wait(tm, &secondTier);
|
|
|
|
});
|
|
|
|
|
2017-12-17 19:34:52 +00:00
|
|
|
eventDriver.timers.set(tm, 1200.msecs, 0.msecs);
|
2016-10-19 20:00:32 +00:00
|
|
|
|
|
|
|
ExitReason er;
|
|
|
|
do er = eventDriver.core.processEvents(Duration.max);
|
|
|
|
while (er == ExitReason.idle);
|
2017-06-10 08:28:16 +00:00
|
|
|
assert(er == ExitReason.outOfWaiters);
|
2016-10-19 20:00:32 +00:00
|
|
|
assert(s_done);
|
|
|
|
s_done = false;
|
|
|
|
}
|