Added support for graceful shutdown

master
parent 490cfe85d6
commit e8b78156b7

@ -18,6 +18,9 @@ public struct EngineSettings
/* If `holdOffMode` is `SLEEP` then set the duration for the sleep */
Duration sleepTime;
/* Calling `shutdown()` will wait for any pending events to be dispatched before shutting down */
bool gracefulShutdown;
}
/**

@ -189,6 +189,9 @@ public final class Engine : Thread
defaultSettings.holdOffMode = HoldOffMode.SLEEP;
defaultSettings.sleepTime = dur!("msecs")(200);
/* Do not gracefully shutdown */
defaultSettings.gracefulShutdown = false;
this(defaultSettings);
}
@ -313,6 +316,12 @@ public final class Engine : Thread
{
/* TODO: Insert a lock here, that dispatch should adhere too as well */
/* Wait for any pendings events (if configured) */
if(settings.gracefulShutdown)
{
while(hasPendingEvents()) {}
}
/* Stop the loop */
running = false;
}

Loading…
Cancel
Save