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
)

Parameters

dur Duration

Duration of sleep.

callback void delegate
(
Exception
)
nothrow

a function called when operation finished or an error occurred.

Examples

import dpromise.utils : runEventloop;
import std.datetime : Clock, UTC;

auto startTime = Clock.currTime(UTC());
sleepAsyncWithCallback(100.msecs, (e) nothrow {
  try {
    auto dur = Clock.currTime(UTC()) - startTime;
    assert(dur + 4.msecs > 100.msecs);
    assert(dur - 4.msecs < 100.msecs);
  } catch(Exception e) {}
});

runEventloop();

Meta