From c88964337ad05caae04f31f0d88ef9b33bef861f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 6 Mar 2018 23:39:57 +0100 Subject: [PATCH 1/2] Add test for issue #66. --- tests/issue-66-yield-eventloop-exit.d | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/issue-66-yield-eventloop-exit.d diff --git a/tests/issue-66-yield-eventloop-exit.d b/tests/issue-66-yield-eventloop-exit.d new file mode 100644 index 0000000..dd7ae64 --- /dev/null +++ b/tests/issue-66-yield-eventloop-exit.d @@ -0,0 +1,19 @@ +/+ dub.sdl: + name "tests" + dependency "vibe-core" path=".." ++/ +module tests; + +import vibe.core.core; + +void main() +{ + bool visited = false; + runTask({ + yield(); + visited = true; + exitEventLoop(); + }); + runApplication(); + assert(visited); +} From 66c9aeea57fc2573e97ea26c2f940f63fea74e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 6 Mar 2018 23:41:56 +0100 Subject: [PATCH 2/2] Don't exit event loop prematurely. Fixes #66. Idle processing needs to check whether there are still tasks scheduled to be resumed before setting the exit flag when there are no more waiters (I/O etc.). --- source/vibe/core/core.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index cbef0d0..b34b876 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -1140,8 +1140,8 @@ package(vibe) void performIdleProcessing() if (again) { auto er = eventDriver.core.processEvents(0.seconds); - if (er.among!(ExitReason.exited, ExitReason.outOfWaiters)) { - logDebug("Setting exit flag due to driver signalling exit"); + if (er.among!(ExitReason.exited, ExitReason.outOfWaiters) && s_scheduler.scheduledTaskCount == 0) { + logDebug("Setting exit flag due to driver signalling exit: %s", er); s_exitEventLoop = true; return; }