Fix createTimer() when called with a callback.

This commit is contained in:
Sönke Ludwig 2017-01-30 19:55:34 +01:00
parent c490a354b7
commit f5c2177c5d
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C

View file

@ -886,6 +886,7 @@ Timer createTimer(void delegate() nothrow @safe callback)
auto ret = Timer(eventDriver.timers.create()); auto ret = Timer(eventDriver.timers.create());
if (callback !is null) { if (callback !is null) {
runTask((void delegate() nothrow @safe cb, Timer tm) { runTask((void delegate() nothrow @safe cb, Timer tm) {
while (!tm.unique || tm.pending)
tm.wait(); tm.wait();
cb(); cb();
}, callback, ret); }, callback, ret);
@ -1106,6 +1107,9 @@ struct Timer {
bool opCast() const nothrow { return m_driver !is null; } bool opCast() const nothrow { return m_driver !is null; }
/// Determines if this reference is the only one
@property bool unique() const nothrow { return m_driver ? m_driver.isUnique(m_id) : false; }
/** Resets the timer to the specified timeout /** Resets the timer to the specified timeout
*/ */
void rearm(Duration dur, bool periodic = false) nothrow void rearm(Duration dur, bool periodic = false) nothrow
@ -1120,8 +1124,6 @@ struct Timer {
*/ */
void wait() void wait()
{ {
assert (!m_driver.isPeriodic(m_id), "Cannot wait for a periodic timer.");
if (!this.pending) return;
asyncAwait!(TimerCallback, asyncAwait!(TimerCallback,
cb => m_driver.wait(m_id, cb), cb => m_driver.wait(m_id, cb),
cb => m_driver.cancelWait(m_id) cb => m_driver.cancelWait(m_id)