papa-0.7.0: src/Papa/Unsafe/Async.hs
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}
-- | The functions of "Control.Concurrent.Async" that rethrow one thread's
-- exception in another:
--
-- * @wait@, @waitAny@, @waitEither@, @waitEither_@, @waitBoth@, their @…STM@
-- forms and @waitAnyCancel@, @waitEitherCancel@, which rethrow the
-- exception of the thread waited for in the waiting thread;
-- * @link@, @link2@, @linkOnly@, @link2Only@, which throw it asynchronously,
-- wrapped in 'ExceptionInLinkedThread', into the linked thread, at any
-- point of whatever it is doing.
--
-- "Papa.Async.Control.Concurrent.Async" returns the exception as a value:
-- 'Papa.Async.Control.Concurrent.Async.waitCatch',
-- 'Papa.Async.Control.Concurrent.Async.waitExcept' and the @…Catch@
-- functions.
--
-- @waitAny@, @waitAnySTM@ and @waitAnyCancel@ also wait forever at an empty
-- list.
--
-- This module exports only these functions, and so combines with
-- @import Papa@.
--
-- ==== __Examples__
--
-- @wait@ rethrows the thread's exception:
--
-- >>> E.try (withAsync (E.throwIO (userError "x") :: IO ()) wait) :: IO (Either IOException ())
-- Left user error (x)
--
-- >>> withAsync (pure 3) wait
-- 3
--
-- @since 0.7.0
module Papa.Unsafe.Async (
wait,
waitSTM,
waitAny,
waitAnySTM,
waitAnyCancel,
waitEither,
waitEitherSTM,
waitEither_,
waitEitherSTM_,
waitEitherCancel,
waitBoth,
waitBothSTM,
link,
link2,
linkOnly,
link2Only,
ExceptionInLinkedThread (ExceptionInLinkedThread),
) where
import Control.Concurrent.Async (
ExceptionInLinkedThread (ExceptionInLinkedThread),
link,
link2,
link2Only,
linkOnly,
wait,
waitAny,
waitAnyCancel,
waitAnySTM,
waitBoth,
waitBothSTM,
waitEither,
waitEitherCancel,
waitEitherSTM,
waitEitherSTM_,
waitEither_,
waitSTM,
)
-- $setup
-- >>> :set -XNoImplicitPrelude
-- >>> import Papa.Unsafe
-- >>> import qualified Control.Exception as E