Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libs/polysemy-wire-zoo/src/Wire/Sem/Concurrency/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import Polysemy.Final
import UnliftIO (pooledMapConcurrentlyN, pooledMapConcurrentlyN_)
import Wire.Sem.Concurrency (Concurrency (..), ConcurrencySafety (Safe))

------------------------------------------------------------------------------

-- | Safely perform concurrency that wraps only IO effects.
performConcurrency ::
Member (Final IO) r =>
Sem (Concurrency 'Safe ': r) a ->
Sem r a
performConcurrency = unsafelyPerformConcurrency

------------------------------------------------------------------------------

-- | VERY UNSAFELY perform concurrency in Polysemy. This is likely to lead to
-- obscure bugs. See the notes on 'Concurrency' to get a better understanding
-- of what can go wrong here.
unsafelyPerformConcurrency ::
Member (Final IO) r =>
Sem (Concurrency safe ': r) a ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Imports
import Polysemy
import Wire.Sem.Concurrency

------------------------------------------------------------------------------

-- | Safely perform "concurrency" by doing it sequentially.
sequentiallyPerformConcurrency :: Sem (Concurrency safe ': r) a -> Sem r a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have been 'Safe instead of safe in the type :: Sem (Concurrency safe ': r) a -> Sem r a?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isovector , I guess this has slipped your attention because I merged this before you got a chance to reply. Here's just a reminder.

sequentiallyPerformConcurrency = interpretH $ \case
UnsafePooledMapConcurrentlyN _ f t -> do
Expand Down