Skip to content

Commit 8dd8d76

Browse files
committed
STM (Maybe result)
1 parent 54b3238 commit 8dd8d76

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

unfork/Unfork.hs

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Control.Exception.Safe (bracket)
2020

2121
import Control.Monad (guard)
2222

23-
import Control.Monad.STM (STM, atomically, retry)
23+
import Control.Monad.STM (STM, atomically)
2424

2525
import Control.Concurrent.Async (concurrently)
2626

@@ -90,7 +90,7 @@ unforkAsyncVoidIO action =
9090
unforkAsyncSTM ::
9191
(task -> IO result)
9292
-- ^ Action that needs to be run serially
93-
-> ((task -> STM (STM result)) -> IO conclusion)
93+
-> ((task -> STM (STM (Maybe result))) -> IO conclusion)
9494
-- ^ Continuation with a thread-safe version of the action
9595
-> IO conclusion
9696
unforkAsyncSTM action =
@@ -99,11 +99,7 @@ unforkAsyncSTM action =
9999
threadSafeAction run arg = do
100100
resultVar <- newTVar Nothing
101101
enqueue run Task{ arg, resultVar }
102-
pure do
103-
m <- readTVar resultVar
104-
case m of
105-
Nothing -> retry
106-
Just x -> pure x
102+
pure (readTVar resultVar)
107103

108104
step Task{ arg, resultVar } = do
109105
b <- action arg

0 commit comments

Comments
 (0)