mirror of https://github.com/deavmi/eventy.git
Added support for graceful shutdown
This commit is contained in:
parent
490cfe85d6
commit
e8b78156b7
|
@ -18,6 +18,9 @@ public struct EngineSettings
|
||||||
|
|
||||||
/* If `holdOffMode` is `SLEEP` then set the duration for the sleep */
|
/* If `holdOffMode` is `SLEEP` then set the duration for the sleep */
|
||||||
Duration sleepTime;
|
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.holdOffMode = HoldOffMode.SLEEP;
|
||||||
defaultSettings.sleepTime = dur!("msecs")(200);
|
defaultSettings.sleepTime = dur!("msecs")(200);
|
||||||
|
|
||||||
|
/* Do not gracefully shutdown */
|
||||||
|
defaultSettings.gracefulShutdown = false;
|
||||||
|
|
||||||
this(defaultSettings);
|
this(defaultSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +316,12 @@ public final class Engine : Thread
|
||||||
{
|
{
|
||||||
/* TODO: Insert a lock here, that dispatch should adhere too as well */
|
/* 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 */
|
/* Stop the loop */
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue