Skip to content

Commit

Permalink
use block comment
Browse files Browse the repository at this point in the history
  • Loading branch information
soulomoon committed Jun 8, 2024
1 parent a16d04a commit c832da3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ghcide/src/Development/IDE/Core/WorkerThread.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c832da3

Please sign in to comment.