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