Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
834b9cfa
Commit
834b9cfa
authored
Sep 26, 2010
by
basvandijk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add throwSTM :: Exception e => e -> STM a
parent
55d15377
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
libraries/base/GHC/Conc.lhs
libraries/base/GHC/Conc.lhs
+1
-0
libraries/base/GHC/Conc/Sync.lhs
libraries/base/GHC/Conc/Sync.lhs
+22
-0
No files found.
libraries/base/GHC/Conc.lhs
View file @
834b9cfa
...
...
@@ -58,6 +58,7 @@ module GHC.Conc
, atomically -- :: STM a -> IO a
, retry -- :: STM a
, orElse -- :: STM a -> STM a -> STM a
, throwSTM -- :: Exception e => e -> STM a
, catchSTM -- :: Exception e => STM a -> (e -> STM a) -> STM a
, alwaysSucceeds -- :: STM a -> STM ()
, always -- :: STM Bool -> STM ()
...
...
libraries/base/GHC/Conc/Sync.lhs
View file @
834b9cfa
...
...
@@ -52,6 +52,7 @@ module GHC.Conc.Sync
, atomically -- :: STM a -> IO a
, retry -- :: STM a
, orElse -- :: STM a -> STM a -> STM a
, throwSTM -- :: Exception e => e -> STM a
, catchSTM -- :: Exception e => STM a -> (e -> STM a) -> STM a
, alwaysSucceeds -- :: STM a -> STM ()
, always -- :: STM Bool -> STM ()
...
...
@@ -509,6 +510,27 @@ retry = STM $ \s# -> retry# s#
orElse :: STM a -> STM a -> STM a
orElse (STM m) e = STM $ \s -> catchRetry# m (unSTM e) s
-- | A variant of 'throw' that can only be used within the 'STM' monad.
--
-- Throwing an exception in @STM@ aborts the transaction and propagates the
-- exception.
--
-- Although 'throwSTM' has a type that is an instance of the type of 'throw', the
-- two functions are subtly different:
--
-- > throw e `seq` x ===> throw e
-- > throwSTM e `seq` x ===> x
--
-- The first example will cause the exception @e@ to be raised,
-- whereas the second one won\'t. In fact, 'throwSTM' will only cause
-- an exception to be raised when it is used within the 'STM' monad.
-- The 'throwSTM' variant should be used in preference to 'throw' to
-- raise an exception within the 'STM' monad because it guarantees
-- ordering with respect to other 'STM' operations, whereas 'throw'
-- does not.
throwSTM :: Exception e => e -> STM a
throwSTM e = STM $ raiseIO# (toException e)
-- |Exception handling within STM actions.
catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a
catchSTM (STM m) handler = STM $ catchSTM# m handler'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment