From f5c2177c5da393d801b1ad1fa37df047ccd979d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 30 Jan 2017 19:55:34 +0100 Subject: [PATCH] Fix createTimer() when called with a callback. --- source/vibe/core/core.d | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index d02bc9e..ef1d9b6 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -886,7 +886,8 @@ Timer createTimer(void delegate() nothrow @safe callback) auto ret = Timer(eventDriver.timers.create()); if (callback !is null) { runTask((void delegate() nothrow @safe cb, Timer tm) { - tm.wait(); + while (!tm.unique || tm.pending) + tm.wait(); cb(); }, callback, ret); } @@ -1106,6 +1107,9 @@ struct Timer { 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 */ void rearm(Duration dur, bool periodic = false) nothrow @@ -1120,8 +1124,6 @@ struct Timer { */ void wait() { - assert (!m_driver.isPeriodic(m_id), "Cannot wait for a periodic timer."); - if (!this.pending) return; asyncAwait!(TimerCallback, cb => m_driver.wait(m_id, cb), cb => m_driver.cancelWait(m_id)