@@ -26,7 +26,7 @@ module Control.Monad.Aff
26
26
import Control.Monad.Cont.Class (MonadCont )
27
27
import Control.Monad.Eff (Eff ())
28
28
import Control.Monad.Eff.Class (MonadEff , liftEff )
29
- import Control.Monad.Eff.Exception (Error (), EXCEPTION (), catchException , error )
29
+ import Control.Monad.Eff.Exception (Error (), EXCEPTION (), catchException , throwException , error )
30
30
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff )
31
31
import Control.Monad.Error.Class (MonadError , throwError )
32
32
import Control.Monad.Rec.Class (MonadRec , tailRecM )
@@ -65,9 +65,20 @@ module Control.Monad.Aff
65
65
cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
66
66
67
67
-- | Converts the asynchronous computation into a synchronous one. All values
68
- -- | and errors are ignored.
69
- launchAff :: forall e a. Aff e a -> Eff e Unit
70
- launchAff = runAff (const (pure unit)) (const (pure unit))
68
+ -- | are ignored, and if the computation produces an error, it is thrown.
69
+ -- |
70
+ -- | Catching exceptions by using `catchException` with the resulting Eff
71
+ -- | computation is not recommended, as exceptions may end up being thrown
72
+ -- | asynchronously, in which case they cannot be caught.
73
+ -- |
74
+ -- | If you do need to handle exceptions, you can use `runAff` instead, or
75
+ -- | you can handle the exception within the Aff computation, using
76
+ -- | `catchError` (or any of the other mechanisms).
77
+ launchAff :: forall e a. Aff e a -> Eff (err :: EXCEPTION | e ) Unit
78
+ launchAff = runAff throwException (const (pure unit)) <<< liftEx
79
+ where
80
+ liftEx :: forall e a. Aff e a -> Aff (err :: EXCEPTION | e ) a
81
+ liftEx = _unsafeInterleaveAff
71
82
72
83
-- | Runs the asynchronous computation. You must supply an error callback and a
73
84
-- | success callback.
0 commit comments