@@ -1,8 +1,8 @@
1{-# LANGUAGE UndecidableInstances #-}
1{-# LANGUAGE UndecidableInstances #-}
2−-- | Lifted version of "Control.Concurrent.Async".
3−module Effectful.Concurrent.Async
2+module Effectful.Async
4− ( Concurrent
3+ ( -- * Async effect
5− , runConcurrent
4+ AsyncE
7 -- * Asynchronous actions
7 -- * Asynchronous actions
@@ -76,37 +76,52 @@ import Control.Concurrent (threadDelay)
76import Control.Concurrent.Async (Async)
76import Control.Concurrent.Async (Async)
77import Control.Exception (Exception, SomeException)
77import Control.Exception (Exception, SomeException)
78import Control.Monad (forever)
78import Control.Monad (forever)
79−import Data.Kind (Type)
79+import Data.Kind
80import qualified Control.Concurrent.Async as A
80import qualified Control.Concurrent.Async as A
81import qualified UnliftIO.Async as U
81import qualified UnliftIO.Async as U
82import qualified UnliftIO.Internals.Async as I
82import qualified UnliftIO.Internals.Async as I
84−import Effectful.Concurrent.Effect
84+import Effectful.Internal.Effect
85−import Effectful.Dispatch.Static
85+import Effectful.Internal.Env
86−import Effectful.Monad
86+import Effectful.Internal.Monad
88+-- | Run 'Eff' operations asynchronously via the @async@ library.
90+-- /Note:/ thread local state changes in 'Eff' operations run asynchronously
91+-- will not affect the parent thread.
93+-- /TODO:/ write about 'AsyncE' not respecting scoped operations.
94+data AsyncE :: Effect where
97+runAsyncE :: IOE :> es => Eff (AsyncE : es) a -> Eff es a
98+runAsyncE = evalEffect (IdE AsyncE)
100+----------------------------------------
88-- | Lifted 'A.async'.
103-- | Lifted 'A.async'.
89−async :: Concurrent :> es => Eff es a -> Eff es (Async a)
104+async :: AsyncE :> es => Eff es a -> Eff es (Async a)
90async = liftAsync A.async
105async = liftAsync A.async
92-- | Lifted 'A.asyncBound'.
107-- | Lifted 'A.asyncBound'.
93−asyncBound :: Concurrent :> es => Eff es a -> Eff es (Async a)
108+asyncBound :: AsyncE :> es => Eff es a -> Eff es (Async a)
94asyncBound = liftAsync A.asyncBound
109asyncBound = liftAsync A.asyncBound
96-- | Lifted 'A.asyncOn'.
111-- | Lifted 'A.asyncOn'.
97−asyncOn :: Concurrent :> es => Int -> Eff es a -> Eff es (Async a)
112+asyncOn :: AsyncE :> es => Int -> Eff es a -> Eff es (Async a)
98asyncOn cpu = liftAsync (A.asyncOn cpu)
113asyncOn cpu = liftAsync (A.asyncOn cpu)
100-- | Lifted 'A.asyncWithUnmask'.
115-- | Lifted 'A.asyncWithUnmask'.
101asyncWithUnmask
116asyncWithUnmask
102− :: Concurrent :> es
117+ :: AsyncE :> es
103 => ((forall b. Eff es b -> Eff es b) -> Eff es a)
118 => ((forall b. Eff es b -> Eff es b) -> Eff es a)
104 -> Eff es (Async a)
119 -> Eff es (Async a)
105asyncWithUnmask = liftAsyncWithUnmask A.asyncWithUnmask
120asyncWithUnmask = liftAsyncWithUnmask A.asyncWithUnmask
107-- | Lifted 'A.asyncOnWithUnmask'.
122-- | Lifted 'A.asyncOnWithUnmask'.
108asyncOnWithUnmask
123asyncOnWithUnmask
109− :: Concurrent :> es
124+ :: AsyncE :> es
111 -> ((forall b. Eff es b -> Eff es b) -> Eff es a)
126 -> ((forall b. Eff es b -> Eff es b) -> Eff es a)
112 -> Eff es (Async a)
127 -> Eff es (Async a)
@@ -114,7 +129,7 @@ asyncOnWithUnmask cpu = liftAsyncWithUnmask (A.asyncOnWithUnmask cpu)
115-- | Lifted 'A.withAsync'.
130-- | Lifted 'A.withAsync'.
117− :: Concurrent :> es
132+ :: AsyncE :> es
118 => Eff es a
133 => Eff es a
119 -> (Async a -> Eff es b)
134 -> (Async a -> Eff es b)
120 -> Eff es b
135 -> Eff es b
@@ -122,7 +137,7 @@ withAsync = liftWithAsync A.withAsync
123-- | Lifted 'A.withAsyncBound'.
138-- | Lifted 'A.withAsyncBound'.
124withAsyncBound
139withAsyncBound
125− :: Concurrent :> es
140+ :: AsyncE :> es
126 => Eff es a
141 => Eff es a
127 -> (Async a -> Eff es b)
142 -> (Async a -> Eff es b)
128 -> Eff es b
143 -> Eff es b
@@ -130,7 +145,7 @@ withAsyncBound = liftWithAsync A.withAsyncBound
131-- | Lifted 'A.withAsyncOn'.
146-- | Lifted 'A.withAsyncOn'.
132withAsyncOn
147withAsyncOn
133− :: Concurrent :> es
148+ :: AsyncE :> es
135 -> Eff es a
150 -> Eff es a
136 -> (Async a -> Eff es b)
151 -> (Async a -> Eff es b)
@@ -139,7 +154,7 @@ withAsyncOn cpu = liftWithAsync (A.withAsyncOn cpu)
140-- | Lifted 'A.withAsyncWithUnmask'.
155-- | Lifted 'A.withAsyncWithUnmask'.
141withAsyncWithUnmask
156withAsyncWithUnmask
142− :: Concurrent :> es
157+ :: AsyncE :> es
143 => ((forall c. Eff es c -> Eff es c) -> Eff es a)
158 => ((forall c. Eff es c -> Eff es c) -> Eff es a)
144 -> (Async a -> Eff es b)
159 -> (Async a -> Eff es b)
145 -> Eff es b
160 -> Eff es b
@@ -147,7 +162,7 @@ withAsyncWithUnmask = liftWithAsyncWithUnmask A.withAsyncWithUnmask
148-- | Lifted 'A.withAsyncOnWithUnmask'.
163-- | Lifted 'A.withAsyncOnWithUnmask'.
149withAsyncOnWithUnmask
164withAsyncOnWithUnmask
150− :: Concurrent :> es
165+ :: AsyncE :> es
152 -> ((forall c. Eff es c -> Eff es c) -> Eff es a)
167 -> ((forall c. Eff es c -> Eff es c) -> Eff es a)
153 -> (Async a -> Eff es b)
168 -> (Async a -> Eff es b)
@@ -155,60 +170,60 @@ withAsyncOnWithUnmask
155withAsyncOnWithUnmask cpu = liftWithAsyncWithUnmask (A.withAsyncOnWithUnmask cpu)
170withAsyncOnWithUnmask cpu = liftWithAsyncWithUnmask (A.withAsyncOnWithUnmask cpu)
157-- | Lifted 'A.wait'.
172-- | Lifted 'A.wait'.
158−wait :: Concurrent :> es => Async a -> Eff es a
173+wait :: AsyncE :> es => Async a -> Eff es a
159wait = unsafeEff_ . A.wait
174wait = unsafeEff_ . A.wait
161-- | Lifted 'A.poll'.
176-- | Lifted 'A.poll'.
163− :: Concurrent :> es
178+ :: AsyncE :> es
164 => Async a
179 => Async a
165 -> Eff es (Maybe (Either SomeException a))
180 -> Eff es (Maybe (Either SomeException a))
166poll = unsafeEff_ . A.poll
181poll = unsafeEff_ . A.poll
168-- | Lifted 'A.cancel'.
183-- | Lifted 'A.cancel'.
169−cancel :: Concurrent :> es => Async a -> Eff es ()
184+cancel :: AsyncE :> es => Async a -> Eff es ()
170cancel = unsafeEff_ . A.cancel
185cancel = unsafeEff_ . A.cancel
172-- | Lifted 'A.cancelWith'.
187-- | Lifted 'A.cancelWith'.
173−cancelWith :: (Exception e, Concurrent :> es) => Async a -> e -> Eff es ()
188+cancelWith :: (Exception e, AsyncE :> es) => Async a -> e -> Eff es ()
174cancelWith a = unsafeEff_ . A.cancelWith a
189cancelWith a = unsafeEff_ . A.cancelWith a
176-- | Lifted 'A.uninterruptibleCancel'.
191-- | Lifted 'A.uninterruptibleCancel'.
177−uninterruptibleCancel :: Concurrent :> es => Async a -> Eff es ()
192+uninterruptibleCancel :: AsyncE :> es => Async a -> Eff es ()
178uninterruptibleCancel = unsafeEff_ . A.uninterruptibleCancel
193uninterruptibleCancel = unsafeEff_ . A.uninterruptibleCancel
180-- | Lifted 'A.waitCatch'.
195-- | Lifted 'A.waitCatch'.
182− :: Concurrent :> es
197+ :: AsyncE :> es
183 => Async a
198 => Async a
184 -> Eff es (Either SomeException a)
199 -> Eff es (Either SomeException a)
185waitCatch = unsafeEff_ . A.waitCatch
200waitCatch = unsafeEff_ . A.waitCatch
187-- | Lifted 'A.waitAny'.
202-- | Lifted 'A.waitAny'.
188−waitAny :: Concurrent :> es => [Async a] -> Eff es (Async a, a)
203+waitAny :: AsyncE :> es => [Async a] -> Eff es (Async a, a)
189waitAny = unsafeEff_ . A.waitAny
204waitAny = unsafeEff_ . A.waitAny
191-- | Lifted 'A.waitAnyCatch'.
206-- | Lifted 'A.waitAnyCatch'.
192waitAnyCatch
207waitAnyCatch
193− :: Concurrent :> es
208+ :: AsyncE :> es
194 => [Async a]
209 => [Async a]
195 -> Eff es (Async a, Either SomeException a)
210 -> Eff es (Async a, Either SomeException a)
196waitAnyCatch = unsafeEff_ . A.waitAnyCatch
211waitAnyCatch = unsafeEff_ . A.waitAnyCatch
198-- | Lifted 'A.waitAnyCancel'.
213-- | Lifted 'A.waitAnyCancel'.
199−waitAnyCancel :: Concurrent :> es => [Async a] -> Eff es (Async a, a)
214+waitAnyCancel :: AsyncE :> es => [Async a] -> Eff es (Async a, a)
200waitAnyCancel = unsafeEff_ . A.waitAnyCancel
215waitAnyCancel = unsafeEff_ . A.waitAnyCancel
202-- | Lifted 'A.waitAnyCatchCancel'.
217-- | Lifted 'A.waitAnyCatchCancel'.
203waitAnyCatchCancel
218waitAnyCatchCancel
204− :: Concurrent :> es
219+ :: AsyncE :> es
205 => [Async a]
220 => [Async a]
206 -> Eff es (Async a, Either SomeException a)
221 -> Eff es (Async a, Either SomeException a)
207waitAnyCatchCancel = unsafeEff_ . A.waitAnyCatchCancel
222waitAnyCatchCancel = unsafeEff_ . A.waitAnyCatchCancel
209-- | Lifted 'A.waitEither'.
224-- | Lifted 'A.waitEither'.
210waitEither
225waitEither
211− :: Concurrent :> es
226+ :: AsyncE :> es
212 => Async a
227 => Async a
213 -> Async b
228 -> Async b
214 -> Eff es (Either a b)
229 -> Eff es (Either a b)
@@ -216,7 +231,7 @@ waitEither a b = unsafeEff_ $ A.waitEither a b
217-- | Lifted 'A.waitEitherCatch'.
232-- | Lifted 'A.waitEitherCatch'.
218waitEitherCatch
233waitEitherCatch
219− :: Concurrent :> es
234+ :: AsyncE :> es
220 => Async a
235 => Async a
221 -> Async b
236 -> Async b
222 -> Eff es (Either (Either SomeException a) (Either SomeException b))
237 -> Eff es (Either (Either SomeException a) (Either SomeException b))
@@ -224,7 +239,7 @@ waitEitherCatch a b = unsafeEff_ $ A.waitEitherCatch a b
225-- | Lifted 'A.waitEitherCancel'.
240-- | Lifted 'A.waitEitherCancel'.
226waitEitherCancel
241waitEitherCancel
227− :: Concurrent :> es
242+ :: AsyncE :> es
228 => Async a
243 => Async a
229 -> Async b
244 -> Async b
230 -> Eff es (Either a b)
245 -> Eff es (Either a b)
@@ -232,53 +247,53 @@ waitEitherCancel a b = unsafeEff_ $ A.waitEitherCancel a b
233-- | Lifted 'A.waitEitherCatchCancel'.
248-- | Lifted 'A.waitEitherCatchCancel'.
234waitEitherCatchCancel
249waitEitherCatchCancel
235− :: Concurrent :> es
250+ :: AsyncE :> es
236 => Async a
251 => Async a
237 -> Async b
252 -> Async b
238 -> Eff es (Either (Either SomeException a) (Either SomeException b))
253 -> Eff es (Either (Either SomeException a) (Either SomeException b))
239waitEitherCatchCancel a b = unsafeEff_ $ A.waitEitherCatch a b
254waitEitherCatchCancel a b = unsafeEff_ $ A.waitEitherCatch a b
241-- | Lifted 'A.waitEither_'.
256-- | Lifted 'A.waitEither_'.
242−waitEither_ :: Concurrent :> es => Async a -> Async b -> Eff es ()
257+waitEither_ :: AsyncE :> es => Async a -> Async b -> Eff es ()
243waitEither_ a b = unsafeEff_ $ A.waitEither_ a b
258waitEither_ a b = unsafeEff_ $ A.waitEither_ a b
245-- | Lifted 'A.waitBoth'.
260-- | Lifted 'A.waitBoth'.
246−waitBoth :: Concurrent :> es => Async a -> Async b -> Eff es (a, b)
261+waitBoth :: AsyncE :> es => Async a -> Async b -> Eff es (a, b)
247waitBoth a b = unsafeEff_ $ A.waitBoth a b
262waitBoth a b = unsafeEff_ $ A.waitBoth a b
249-- | Lifted 'A.link'.
264-- | Lifted 'A.link'.
250−link :: Concurrent :> es => Async a -> Eff es ()
265+link :: AsyncE :> es => Async a -> Eff es ()
251link = unsafeEff_ . A.link
266link = unsafeEff_ . A.link
253-- | Lifted 'A.linkOnly'.
268-- | Lifted 'A.linkOnly'.
254−linkOnly :: Concurrent :> es => (SomeException -> Bool) -> Async a -> Eff es ()
269+linkOnly :: AsyncE :> es => (SomeException -> Bool) -> Async a -> Eff es ()
255linkOnly f = unsafeEff_ . A.linkOnly f
270linkOnly f = unsafeEff_ . A.linkOnly f
257-- | Lifted 'A.link2'.
272-- | Lifted 'A.link2'.
258−link2 :: Concurrent :> es => Async a -> Async b -> Eff es ()
273+link2 :: AsyncE :> es => Async a -> Async b -> Eff es ()
259link2 a b = unsafeEff_ $ A.link2 a b
274link2 a b = unsafeEff_ $ A.link2 a b
261-- | Lifted 'A.link2Only'.
276-- | Lifted 'A.link2Only'.
262−link2Only :: Concurrent :> es => (SomeException -> Bool) -> Async a -> Async b -> Eff es ()
277+link2Only :: AsyncE :> es => (SomeException -> Bool) -> Async a -> Async b -> Eff es ()
263link2Only f a b = unsafeEff_ $ A.link2Only f a b
278link2Only f a b = unsafeEff_ $ A.link2Only f a b
265-- | Lifted 'A.race'.
280-- | Lifted 'A.race'.
266−race :: Concurrent :> es => Eff es a -> Eff es b -> Eff es (Either a b)
281+race :: AsyncE :> es => Eff es a -> Eff es b -> Eff es (Either a b)
267race ma mb = unsafeEff $ \es -> do
282race ma mb = unsafeEff $ \es -> do
268 A.race (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
283 A.race (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
270-- | Lifted 'A.race_'.
285-- | Lifted 'A.race_'.
271−race_ :: Concurrent :> es => Eff es a -> Eff es b -> Eff es ()
286+race_ :: AsyncE :> es => Eff es a -> Eff es b -> Eff es ()
272race_ ma mb = unsafeEff $ \es -> do
287race_ ma mb = unsafeEff $ \es -> do
273 A.race_ (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
288 A.race_ (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
275-- | Lifted 'A.concurrently'.
290-- | Lifted 'A.concurrently'.
276−concurrently :: Concurrent :> es => Eff es a -> Eff es b -> Eff es (a, b)
291+concurrently :: AsyncE :> es => Eff es a -> Eff es b -> Eff es (a, b)
277concurrently ma mb = unsafeEff $ \es -> do
292concurrently ma mb = unsafeEff $ \es -> do
278 A.concurrently (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
293 A.concurrently (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
280-- | Lifted 'A.concurrently_'.
295-- | Lifted 'A.concurrently_'.
281−concurrently_ :: Concurrent :> es => Eff es a -> Eff es b -> Eff es ()
296+concurrently_ :: AsyncE :> es => Eff es a -> Eff es b -> Eff es ()
282concurrently_ ma mb = unsafeEff $ \es -> do
297concurrently_ ma mb = unsafeEff $ \es -> do
283 A.concurrently_ (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
298 A.concurrently_ (unEff ma =<< cloneEnv es) (unEff mb =<< cloneEnv es)
@@ -288,7 +303,7 @@ concurrently_ ma mb = unsafeEff $ \es -> do
289-- | Lifted 'A.mapConcurrently'.
304-- | Lifted 'A.mapConcurrently'.
290mapConcurrently
305mapConcurrently
291− :: (Traversable f, Concurrent :> es)
306+ :: (Traversable f, AsyncE :> es)
292 => (a -> Eff es b)
307 => (a -> Eff es b)
294 -> Eff es (f b)
309 -> Eff es (f b)
@@ -297,7 +312,7 @@ mapConcurrently f t = unsafeEff $ \es -> do
298-- | Lifted 'A.mapConcurrently_'.
313-- | Lifted 'A.mapConcurrently_'.
299mapConcurrently_
314mapConcurrently_
300− :: (Foldable f, Concurrent :> es)
315+ :: (Foldable f, AsyncE :> es)
301 => (a -> Eff es b)
316 => (a -> Eff es b)
303 -> Eff es ()
318 -> Eff es ()
@@ -306,7 +321,7 @@ mapConcurrently_ f t = unsafeEff $ \es -> do
307-- | Lifted 'A.forConcurrently'.
322-- | Lifted 'A.forConcurrently'.
308forConcurrently
323forConcurrently
309− :: (Traversable f, Concurrent :> es)
324+ :: (Traversable f, AsyncE :> es)
311 -> (a -> Eff es b)
326 -> (a -> Eff es b)
312 -> Eff es (f b)
327 -> Eff es (f b)
@@ -315,7 +330,7 @@ forConcurrently t f = unsafeEff $ \es -> do
316-- | Lifted 'A.forConcurrently_'.
331-- | Lifted 'A.forConcurrently_'.
317forConcurrently_
332forConcurrently_
318− :: (Foldable f, Concurrent :> es)
333+ :: (Foldable f, AsyncE :> es)
320 -> (a -> Eff es b)
335 -> (a -> Eff es b)
321 -> Eff es ()
336 -> Eff es ()
@@ -323,12 +338,12 @@ forConcurrently_ t f = unsafeEff $ \es -> do
323 U.forConcurrently_ t (\a -> unEff (f a) =<< cloneEnv es)
338 U.forConcurrently_ t (\a -> unEff (f a) =<< cloneEnv es)
325-- | Lifted 'A.replicateConcurrently'.
340-- | Lifted 'A.replicateConcurrently'.
326−replicateConcurrently :: Concurrent :> es => Int -> Eff es a -> Eff es [a]
341+replicateConcurrently :: AsyncE :> es => Int -> Eff es a -> Eff es [a]
327replicateConcurrently n f = unsafeEff $ \es -> do
342replicateConcurrently n f = unsafeEff $ \es -> do
328 U.replicateConcurrently n (unEff f =<< cloneEnv es)
343 U.replicateConcurrently n (unEff f =<< cloneEnv es)
330-- | Lifted 'A.replicateConcurrently_'.
345-- | Lifted 'A.replicateConcurrently_'.
331−replicateConcurrently_ :: Concurrent :> es => Int -> Eff es a -> Eff es ()
346+replicateConcurrently_ :: AsyncE :> es => Int -> Eff es a -> Eff es ()
332replicateConcurrently_ n f = unsafeEff $ \es -> do
347replicateConcurrently_ n f = unsafeEff $ \es -> do
333 U.replicateConcurrently_ n (unEff f =<< cloneEnv es)
348 U.replicateConcurrently_ n (unEff f =<< cloneEnv es)
@@ -337,7 +352,7 @@ replicateConcurrently_ n f = unsafeEff $ \es -> do
338-- | Lifted 'U.pooledMapConcurrentlyN'.
353-- | Lifted 'U.pooledMapConcurrentlyN'.
339pooledMapConcurrentlyN
354pooledMapConcurrentlyN
340− :: (Concurrent :> es, Traversable t)
355+ :: (AsyncE :> es, Traversable t)
342 -> (a -> Eff es b)
357 -> (a -> Eff es b)
@@ -347,7 +362,7 @@ pooledMapConcurrentlyN threads f t = unsafeEff $ \es -> do
348-- | Lifted 'U.pooledMapConcurrently'.
363-- | Lifted 'U.pooledMapConcurrently'.
349pooledMapConcurrently
364pooledMapConcurrently
350− :: (Concurrent :> es, Traversable t)
365+ :: (AsyncE :> es, Traversable t)
351 => (a -> Eff es b)
366 => (a -> Eff es b)
353 -> Eff es (t b)
368 -> Eff es (t b)
@@ -356,7 +371,7 @@ pooledMapConcurrently f t = unsafeEff $ \es -> do
357-- | Lifted 'U.pooledMapConcurrentlyN'.
372-- | Lifted 'U.pooledMapConcurrentlyN'.
358pooledMapConcurrentlyN_
373pooledMapConcurrentlyN_
359− :: (Concurrent :> es, Foldable f)
374+ :: (AsyncE :> es, Foldable f)
361 -> (a -> Eff es b)
376 -> (a -> Eff es b)
@@ -366,7 +381,7 @@ pooledMapConcurrentlyN_ threads f t = unsafeEff $ \es -> do
367-- | Lifted 'U.pooledMapConcurrently_'.
382-- | Lifted 'U.pooledMapConcurrently_'.
368pooledMapConcurrently_
383pooledMapConcurrently_
369− :: (Concurrent :> es, Foldable f)
384+ :: (AsyncE :> es, Foldable f)
370 => (a -> Eff es b)
385 => (a -> Eff es b)
372 -> Eff es ()
387 -> Eff es ()
@@ -375,7 +390,7 @@ pooledMapConcurrently_ f t = unsafeEff $ \es -> do
376-- | Lifted 'U.pooledForConcurrentlyN'.
391-- | Lifted 'U.pooledForConcurrentlyN'.
377pooledForConcurrentlyN
392pooledForConcurrentlyN
378− :: (Concurrent :> es, Traversable t)
393+ :: (AsyncE :> es, Traversable t)
381 -> (a -> Eff es b)
396 -> (a -> Eff es b)
@@ -385,7 +400,7 @@ pooledForConcurrentlyN threads t f = unsafeEff $ \es -> do
386-- | Lifted 'U.pooledForConcurrently'.
401-- | Lifted 'U.pooledForConcurrently'.
387pooledForConcurrently
402pooledForConcurrently
388− :: (Concurrent :> es, Traversable t)
403+ :: (AsyncE :> es, Traversable t)
390 -> (a -> Eff es b)
405 -> (a -> Eff es b)
391 -> Eff es (t b)
406 -> Eff es (t b)
@@ -394,7 +409,7 @@ pooledForConcurrently t f = unsafeEff $ \es -> do
395-- | Lifted 'U.pooledForConcurrentlyN'.
410-- | Lifted 'U.pooledForConcurrentlyN'.
396pooledForConcurrentlyN_
411pooledForConcurrentlyN_
397− :: (Concurrent :> es, Foldable f)
412+ :: (AsyncE :> es, Foldable f)
400 -> (a -> Eff es b)
415 -> (a -> Eff es b)
@@ -404,7 +419,7 @@ pooledForConcurrentlyN_ threads t f = unsafeEff $ \es -> do
405-- | Lifted 'U.pooledForConcurrently_'.
420-- | Lifted 'U.pooledForConcurrently_'.
406pooledForConcurrently_
421pooledForConcurrently_
407− :: (Concurrent :> es, Foldable f)
422+ :: (AsyncE :> es, Foldable f)
409 -> (a -> Eff es b)
424 -> (a -> Eff es b)
410 -> Eff es ()
425 -> Eff es ()
@@ -412,22 +427,22 @@ pooledForConcurrently_ t f = unsafeEff $ \es -> do
412 U.pooledForConcurrently_ t (\a -> unEff (f a) =<< cloneEnv es)
427 U.pooledForConcurrently_ t (\a -> unEff (f a) =<< cloneEnv es)
414-- | Lifted 'U.pooledReplicateConcurrentlyN'.
429-- | Lifted 'U.pooledReplicateConcurrentlyN'.
415−pooledReplicateConcurrentlyN :: Concurrent :> es => Int -> Int -> Eff es a -> Eff es [a]
430+pooledReplicateConcurrentlyN :: AsyncE :> es => Int -> Int -> Eff es a -> Eff es [a]
416pooledReplicateConcurrentlyN threads n f = unsafeEff $ \es -> do
431pooledReplicateConcurrentlyN threads n f = unsafeEff $ \es -> do
417 U.pooledReplicateConcurrentlyN threads n (unEff f =<< cloneEnv es)
432 U.pooledReplicateConcurrentlyN threads n (unEff f =<< cloneEnv es)
419-- | Lifted 'U.pooledReplicateConcurrently'.
434-- | Lifted 'U.pooledReplicateConcurrently'.
420−pooledReplicateConcurrently :: Concurrent :> es => Int -> Eff es a -> Eff es [a]
435+pooledReplicateConcurrently :: AsyncE :> es => Int -> Eff es a -> Eff es [a]
421pooledReplicateConcurrently n f = unsafeEff $ \es -> do
436pooledReplicateConcurrently n f = unsafeEff $ \es -> do
422 U.pooledReplicateConcurrently n (unEff f =<< cloneEnv es)
437 U.pooledReplicateConcurrently n (unEff f =<< cloneEnv es)
424-- | Lifted 'U.pooledReplicateConcurrentlyN_'.
439-- | Lifted 'U.pooledReplicateConcurrentlyN_'.
425−pooledReplicateConcurrentlyN_ :: Concurrent :> es => Int -> Int -> Eff es a -> Eff es ()
440+pooledReplicateConcurrentlyN_ :: AsyncE :> es => Int -> Int -> Eff es a -> Eff es ()
426pooledReplicateConcurrentlyN_ threads n f = unsafeEff $ \es -> do
441pooledReplicateConcurrentlyN_ threads n f = unsafeEff $ \es -> do
427 U.pooledReplicateConcurrentlyN_ threads n (unEff f =<< cloneEnv es)
442 U.pooledReplicateConcurrentlyN_ threads n (unEff f =<< cloneEnv es)
429-- | Lifted 'U.pooledReplicateConcurrently_'.
444-- | Lifted 'U.pooledReplicateConcurrently_'.
430−pooledReplicateConcurrently_ :: Concurrent :> es => Int -> Eff es a -> Eff es ()
445+pooledReplicateConcurrently_ :: AsyncE :> es => Int -> Eff es a -> Eff es ()
431pooledReplicateConcurrently_ n f = unsafeEff $ \es -> do
446pooledReplicateConcurrently_ n f = unsafeEff $ \es -> do
432 U.pooledReplicateConcurrently_ n (unEff f =<< cloneEnv es)
447 U.pooledReplicateConcurrently_ n (unEff f =<< cloneEnv es)
@@ -467,7 +482,7 @@ conc :: Eff es a -> Conc es a
467conc = Action
482conc = Action
469-- | Lifted 'U.runConc'.
484-- | Lifted 'U.runConc'.
470−runConc :: Concurrent :> es => Conc es a -> Eff es a
485+runConc :: AsyncE :> es => Conc es a -> Eff es a
471runConc m = unsafeEff $ \es -> U.runConc (unliftConc es m)
486runConc m = unsafeEff $ \es -> U.runConc (unliftConc es m)
473 unliftConc :: Env es -> Conc es a -> U.Conc IO a
488 unliftConc :: Env es -> Conc es a -> U.Conc IO a
@@ -488,20 +503,20 @@ newtype Concurrently es a = Concurrently { runConcurrently :: Eff es a }
488instance Functor (Concurrently es) where
503instance Functor (Concurrently es) where
489 fmap f (Concurrently a) = Concurrently (fmap f a)
504 fmap f (Concurrently a) = Concurrently (fmap f a)
491−instance Concurrent :> es => Applicative (Concurrently es) where
506+instance AsyncE :> es => Applicative (Concurrently es) where
492 pure = Concurrently . pure
507 pure = Concurrently . pure
493 Concurrently fs <*> Concurrently as =
508 Concurrently fs <*> Concurrently as =
494 Concurrently ((\(f, a) -> f a) <$> concurrently fs as)
509 Concurrently ((\(f, a) -> f a) <$> concurrently fs as)
496−instance Concurrent :> es => Alternative (Concurrently es) where
511+instance AsyncE :> es => Alternative (Concurrently es) where
497 empty = Concurrently . unsafeEff_ . forever $ threadDelay maxBound
512 empty = Concurrently . unsafeEff_ . forever $ threadDelay maxBound
498 Concurrently as <|> Concurrently bs =
513 Concurrently as <|> Concurrently bs =
499 Concurrently (either id id <$> race as bs)
514 Concurrently (either id id <$> race as bs)
501−instance (Concurrent :> es, Semigroup a) => Semigroup (Concurrently es a) where
516+instance (AsyncE :> es, Semigroup a) => Semigroup (Concurrently es a) where
502 (<>) = liftA2 (<>)
517 (<>) = liftA2 (<>)
504−instance (Concurrent :> es, Monoid a) => Monoid (Concurrently es a) where
519+instance (AsyncE :> es, Monoid a) => Monoid (Concurrently es a) where
505 mempty = pure mempty
520 mempty = pure mempty
507----------------------------------------
522----------------------------------------
@@ -519,9 +534,10 @@ liftAsyncWithUnmask
519 :: (((forall b. IO b -> IO b) -> IO a) -> IO (Async a))
534 :: (((forall b. IO b -> IO b) -> IO a) -> IO (Async a))
520 -> ((forall b. Eff es b -> Eff es b) -> Eff es a)
535 -> ((forall b. Eff es b -> Eff es b) -> Eff es a)
521 -> Eff es (Async a)
536 -> Eff es (Async a)
522−liftAsyncWithUnmask fork action = unsafeEff $ \es -> do
537+liftAsyncWithUnmask fork action = do
538+ unsafeWithLiftMapIO $ \liftMap -> unsafeEff $ \es -> do
523− esA <- cloneEnv es
539+ esA <- cloneEnv es
524− fork $ \unmask -> unEff (action $ unsafeLiftMapIO unmask) esA
540+ fork $ \unmask -> unEff (action $ liftMap unmask) esA
526liftWithAsync
542liftWithAsync
527 :: (IO a -> (Async a -> IO b) -> IO b)
543 :: (IO a -> (Async a -> IO b) -> IO b)
@@ -538,7 +554,8 @@ liftWithAsyncWithUnmask
538 -> ((forall c. Eff es c -> Eff es c) -> Eff es a)
554 -> ((forall c. Eff es c -> Eff es c) -> Eff es a)
539 -> (Async a -> Eff es b)
555 -> (Async a -> Eff es b)
540 -> Eff es b
556 -> Eff es b
541−liftWithAsyncWithUnmask withA action k = unsafeEff $ \es -> do
557+liftWithAsyncWithUnmask withA action k = do
558+ unsafeWithLiftMapIO $ \liftMap -> unsafeEff $ \es -> do
542− esA <- cloneEnv es
559+ esA <- cloneEnv es
543− withA (\unmask -> unEff (action $ unsafeLiftMapIO unmask) esA)
560+ withA (\unmask -> unEff (action $ liftMap unmask) esA)
544− (\a -> unEff (k a) es)
561+ (\a -> unEff (k a) es)