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