From c5a6612a4ba26ec7aaf3568037d5b5f939170a67 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 26 Nov 2023 19:23:21 +0200 Subject: [PATCH] Manager - Updated documentation for `stop()` - Added `stop(ErrorType)` which will let you set the error type used for unblocking the `dequeue()` calls - Added `stop_FailedWatcher()` which sets the `ErrorType` to `WATCHER_FAILED` - `shutdownAllQueues()` now takes in a `ErrorType` --- source/tristanable/manager/manager.d | 37 +++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/source/tristanable/manager/manager.d b/source/tristanable/manager/manager.d index 6ed2bad..291e4e5 100644 --- a/source/tristanable/manager/manager.d +++ b/source/tristanable/manager/manager.d @@ -93,20 +93,51 @@ public class Manager * Stops the management of the socket, resulting * in ending the updating of queues and closing * the underlying connection + * + * Calling this will also unblock any calls that + * were blocking whilst doing a `dequeue()` */ public void stop() + { + /* Stop with the given reason */ + stop(ErrorType.MANAGER_SHUTDOWN); + } + + /** + * Only called by the `Watcher` and for + * the purpose of setting a custom error + * type. + * + * Called when the network read fails + */ + void stop_FailedWatcher() + { + /* Stop with the given reason */ + stop(ErrorType.WATCHER_FAILED); + } + + /** + * Stops the watcher service and then + * unblocks all calls to `dequeue()` + * by shutting down each `Queue` + * + * Params: + * reason = the reason for the + * shutdown + */ + private void stop(ErrorType reason) { /* Stop the watcher */ watcher.shutdown(); /* Unblock all `dequeue()` calls */ - shutdownAllQueues(); + shutdownAllQueues(reason); } /** * Shuts down all registered queues */ - protected void shutdownAllQueues() + protected void shutdownAllQueues(ErrorType reason) { /* Lock the queue of queues */ queuesLock.lock(); @@ -121,7 +152,7 @@ public class Manager /* Shutdown each queue */ foreach(Queue queue; this.queues) { - queue.shutdownQueue(ErrorType.MANAGER_SHUTDOWN); + queue.shutdownQueue(reason); } }