sleepAsyncWithCallback

Sleep in asynchronous while dur then calls the callback function.

If an error occurred, the callback function will be called with the error.

nothrow @safe
void
sleepAsyncWithCallback
(
Duration dur
,
void delegate(
Exception
) nothrow
callback
)
in { assert (callback !is null); }

Parameters

dur
Type: Duration

Duration of sleep.

callback
Type: void delegate(
Exception
) nothrow

a function called when operation finished or an error occurred.

Examples

1 import dpromise.utils : runEventloop;
2 import std.datetime : Clock, UTC;
3 
4 auto startTime = Clock.currTime(UTC());
5 sleepAsyncWithCallback(100.msecs, (e) nothrow {
6   try {
7     auto dur = Clock.currTime(UTC()) - startTime;
8     assert(dur + 4.msecs > 100.msecs);
9     assert(dur - 4.msecs < 100.msecs);
10   } catch(Exception e) {}
11 });
12 
13 runEventloop();

Meta