-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename ThreadFailed to Propagating and move it to its own module
- Loading branch information
1 parent
cc554dd
commit 6102681
Showing
5 changed files
with
53 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Ki.Internal.Propagating | ||
( pattern PropagatingFrom, | ||
Tid, | ||
peelOffPropagating, | ||
propagate, | ||
) | ||
where | ||
|
||
import Control.Concurrent (ThreadId) | ||
import Control.Exception (Exception (..), SomeException, asyncExceptionFromException, asyncExceptionToException, throwTo) | ||
|
||
-- Internal exception type thrown by a child thread to its parent, if it fails unexpectedly. | ||
data Propagating = Propagating | ||
{ childId :: {-# UNPACK #-} !Tid, | ||
exception :: !SomeException | ||
} | ||
deriving stock (Show) | ||
|
||
instance Exception Propagating where | ||
toException = asyncExceptionToException | ||
fromException = asyncExceptionFromException | ||
|
||
pattern PropagatingFrom :: Tid -> SomeException | ||
pattern PropagatingFrom childId <- (fromException -> Just Propagating {childId}) | ||
|
||
-- A unique identifier for a thread within a scope. (Internal type alias) | ||
type Tid = | ||
Int | ||
|
||
-- Peel an outer Propagating layer off of some exception, if there is one. | ||
peelOffPropagating :: SomeException -> SomeException | ||
peelOffPropagating e0 = | ||
case fromException e0 of | ||
Just (Propagating _ e1) -> e1 | ||
Nothing -> e0 | ||
|
||
-- @propagate exception child parent@ propagates @exception@ from @child@ to @parent@. | ||
propagate :: SomeException -> Tid -> ThreadId -> IO () | ||
propagate exception childId parentThreadId = | ||
throwTo parentThreadId Propagating {childId, exception} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters