diff --git a/source/eventy/config.d b/source/eventy/config.d index 05aa5c4..dcd1bfc 100644 --- a/source/eventy/config.d +++ b/source/eventy/config.d @@ -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; } /** diff --git a/source/eventy/engine.d b/source/eventy/engine.d index 91c4672..b7d6b82 100644 --- a/source/eventy/engine.d +++ b/source/eventy/engine.d @@ -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; }