@@ -20,8 +20,6 @@ module Control.Monad.Class.MonadAsync
20
20
, linkOnly
21
21
, link2
22
22
, link2Only
23
- , linkTo
24
- , linkToOnly
25
23
, mapConcurrently
26
24
, forConcurrently
27
25
, mapConcurrently_
@@ -366,14 +364,10 @@ instance MonadAsync IO where
366
364
-- Adapted from "Control.Concurrent.Async"
367
365
--
368
366
-- We don't use the implementation of linking from 'Control.Concurrent.Async'
369
- -- directly because:
370
- --
371
- -- 1. If we /did/ use the real implementation, then the mock implementation and
372
- -- the real implementation would not be able to throw the same exception,
373
- -- because the exception type used by the real implementation is
374
- -- 2. We need a generalized form of linking that links an async to an arbitrary
375
- -- thread ('linkTo'), which is exposed only if cabal flag `+non-standard` is
376
- -- used.
367
+ -- directly because if we /did/ use the real implementation, then the mock
368
+ -- implementation and the real implementation would not be able to throw the
369
+ -- same exception, because the exception type used by the real implementation
370
+ -- is
377
371
--
378
372
-- > data ExceptionInLinkedThread =
379
373
-- > forall a . ExceptionInLinkedThread (Async a) SomeException
@@ -410,8 +404,19 @@ link = linkOnly (not . isCancel)
410
404
linkOnly :: forall m a . (MonadAsync m , MonadFork m , MonadMask m )
411
405
=> (SomeException -> Bool ) -> Async m a -> m ()
412
406
linkOnly shouldThrow a = do
413
- me <- myThreadId
414
- linkToOnly me shouldThrow a
407
+ tid <- myThreadId
408
+ void $ forkRepeat (" linkToOnly " <> show linkedThreadId) $ do
409
+ r <- waitCatch a
410
+ case r of
411
+ Left e | shouldThrow e -> throwTo tid (exceptionInLinkedThread e)
412
+ _otherwise -> return ()
413
+ where
414
+ linkedThreadId :: ThreadId m
415
+ linkedThreadId = asyncThreadId a
416
+
417
+ exceptionInLinkedThread :: SomeException -> ExceptionInLinkedThread
418
+ exceptionInLinkedThread =
419
+ ExceptionInLinkedThread (show linkedThreadId)
415
420
416
421
link2 :: (MonadAsync m , MonadFork m , MonadMask m )
417
422
=> Async m a -> Async m b -> m ()
@@ -432,34 +437,6 @@ link2Only shouldThrow left right =
432
437
tl = asyncThreadId left
433
438
tr = asyncThreadId right
434
439
435
- -- | Generalization of 'link' that links an async to an arbitrary thread.
436
- --
437
- -- Non standard (not in 'async' library)
438
- --
439
- linkTo :: (MonadAsync m , MonadFork m , MonadMask m )
440
- => ThreadId m -> Async m a -> m ()
441
- linkTo tid = linkToOnly tid (not . isCancel)
442
-
443
- -- | Generalization of 'linkOnly' that links an async to an arbitrary thread.
444
- --
445
- -- Non standard (not in 'async' library).
446
- --
447
- linkToOnly :: forall m a . (MonadAsync m , MonadFork m , MonadMask m )
448
- => ThreadId m -> (SomeException -> Bool ) -> Async m a -> m ()
449
- linkToOnly tid shouldThrow a = do
450
- void $ forkRepeat (" linkToOnly " <> show linkedThreadId) $ do
451
- r <- waitCatch a
452
- case r of
453
- Left e | shouldThrow e -> throwTo tid (exceptionInLinkedThread e)
454
- _otherwise -> return ()
455
- where
456
- linkedThreadId :: ThreadId m
457
- linkedThreadId = asyncThreadId a
458
-
459
- exceptionInLinkedThread :: SomeException -> ExceptionInLinkedThread
460
- exceptionInLinkedThread =
461
- ExceptionInLinkedThread (show linkedThreadId)
462
-
463
440
isCancel :: SomeException -> Bool
464
441
isCancel e
465
442
| Just AsyncCancelled <- fromException e = True
0 commit comments