From c832da3b55978cdba104dcaa879998fdc13f866a Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 9 Jun 2024 00:04:09 +0800 Subject: [PATCH] use block comment --- .../src/Development/IDE/Core/WorkerThread.hs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/WorkerThread.hs b/ghcide/src/Development/IDE/Core/WorkerThread.hs index 7ccf2b4908..4deafcf911 100644 --- a/ghcide/src/Development/IDE/Core/WorkerThread.hs +++ b/ghcide/src/Development/IDE/Core/WorkerThread.hs @@ -9,19 +9,20 @@ import Control.Concurrent.Strict (newBarrier, signalBarrier, import Control.Monad (forever) import Control.Monad.Cont (ContT (ContT)) --- Note [Serializing runs in separate thread] --- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- We often want to take long-running actions using some resource that cannot be shared. --- In this instance it is useful to have a queue of jobs to run using the resource. --- Like the db writes, session loading in session loader, shake session restarts. --- --- Originally we used various ways to implement this, but it was hard to maintain and error prone. --- Moreover, we can not stop these threads uniformly when we are shutting down the server. --- --- `Development.IDE.Core.WorkerThread` module provides a simple api to implement this easily. --- * `withWorkerQueue`: accepts an action to run in separate thread and returns a `TQueue` to send the actions to run. --- * `awaitRunInThread` : accepts a `TQueue` and an action to run in separate thread and waits for the result. +{- +Note [Serializing runs in separate thread] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +We often want to take long-running actions using some resource that cannot be shared. +In this instance it is useful to have a queue of jobs to run using the resource. +Like the db writes, session loading in session loader, shake session restarts. +Originally we used various ways to implement this, but it was hard to maintain and error prone. +Moreover, we can not stop these threads uniformly when we are shutting down the server. + +`Development.IDE.Core.WorkerThread` module provides a simple api to implement this easily. +* `withWorkerQueue`: accepts an action to run in separate thread and returns a `TQueue` to send the actions to run. +* `awaitRunInThread` : accepts a `TQueue` and an action to run in separate thread and waits for the result. +-} -- | withWorkerQueue creates a new TQueue and runs the workerAction in a separate thread. withWorkerQueue :: (t -> IO a) -> ContT () IO (TQueue t)