Added support for graceful shutdown

This commit is contained in:
Tristan B. Velloza Kildaire 2022-11-26 17:12:41 +02:00
parent 490cfe85d6
commit e8b78156b7
2 changed files with 12 additions and 0 deletions

View File

@ -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;
}
/**

View File

@ -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;
}