From 9e526194e7dd6c1baaacf22791dbf9aa63f59216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 23 Nov 2018 15:51:10 +0100 Subject: [PATCH 1/2] Add test for issue #104. --- tests/issue-104-unreferenced-periodic-timer.d | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/issue-104-unreferenced-periodic-timer.d diff --git a/tests/issue-104-unreferenced-periodic-timer.d b/tests/issue-104-unreferenced-periodic-timer.d new file mode 100644 index 0000000..f14b839 --- /dev/null +++ b/tests/issue-104-unreferenced-periodic-timer.d @@ -0,0 +1,23 @@ +/+ dub.sdl: + name "test" + dependency "vibe-core" path=".." ++/ +module test; + +import vibe.core.core; + +import core.memory; +import core.time; + + +int main() +{ + setTimer(10.seconds, { assert(false, "Event loop didn't exit in time."); }); + + // make sure that periodic timers for which no explicit reference is stored + // are still getting invoked periodically + size_t i = 0; + setTimer(50.msecs, { if (i++ == 3) exitEventLoop(); }, true); + + return runEventLoop(); +} From b5442b5efd7cda350c3b0f669c60a8f1d9daf0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 23 Nov 2018 15:52:18 +0100 Subject: [PATCH 2/2] Make sure that pending but unreferenced timers still invoke their callback. Fixes #104. --- source/vibe/core/core.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index d7f85e3..1ada49c 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -1103,7 +1103,7 @@ struct TimerCallbackHandler { cb(); } - if (!eventDriver.timers.isUnique(timer)) + if (!eventDriver.timers.isUnique(timer) || eventDriver.timers.isPending(timer)) eventDriver.timers.wait(timer, &handle); } }