@@ -9,8 +9,7 @@ module Control.Monad.Aff
9
9
, finally
10
10
, forkAff
11
11
, forkAll
12
- , later
13
- , later'
12
+ , delay
14
13
, launchAff
15
14
, liftEff'
16
15
, makeAff
@@ -25,10 +24,10 @@ import Prelude
25
24
import Control.Alt (class Alt )
26
25
import Control.Alternative (class Alternative )
27
26
import Control.Monad.Aff.Internal (AVBox , AVar , _killVar , _putVar , _takeVar , _makeVar )
28
- import Control.Monad.Eff (Eff )
27
+ import Control.Monad.Eff (Eff , kind Effect )
29
28
import Control.Monad.Eff.Class (class MonadEff )
30
29
import Control.Monad.Eff.Exception (Error , EXCEPTION , throwException , error )
31
- import Control.Monad.Error.Class (class MonadError , throwError )
30
+ import Control.Monad.Error.Class (class MonadThrow , class MonadError , throwError )
32
31
import Control.Monad.Rec.Class (class MonadRec , Step (..))
33
32
import Control.MonadPlus (class MonadZero , class MonadPlus )
34
33
import Control.Parallel (class Parallel )
@@ -39,6 +38,7 @@ import Data.Foldable (class Foldable, foldl)
39
38
import Data.Function.Uncurried (Fn2 , Fn3 , runFn2 , runFn3 )
40
39
import Data.Monoid (class Monoid , mempty )
41
40
import Data.Newtype (class Newtype )
41
+ import Data.Time.Duration (Milliseconds (..))
42
42
import Data.Tuple (Tuple (..), fst , snd )
43
43
44
44
import Unsafe.Coerce (unsafeCoerce )
@@ -47,7 +47,7 @@ import Unsafe.Coerce (unsafeCoerce)
47
47
-- | errors or produces a value of type `a`.
48
48
-- |
49
49
-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
50
- foreign import data Aff :: # ! -> * -> *
50
+ foreign import data Aff :: # Effect -> Type -> Type
51
51
52
52
-- | A pure asynchronous computation, having no effects other than
53
53
-- | asynchronous computation.
@@ -80,12 +80,12 @@ cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
80
80
-- | If you do need to handle exceptions, you can use `runAff` instead, or
81
81
-- | you can handle the exception within the Aff computation, using
82
82
-- | `catchError` (or any of the other mechanisms).
83
- launchAff :: forall e a . Aff e a -> Eff (err :: EXCEPTION | e ) (Canceler e )
83
+ launchAff :: forall e a . Aff e a -> Eff (exception :: EXCEPTION | e ) (Canceler e )
84
84
launchAff = lowerEx <<< runAff throwException (const (pure unit)) <<< liftEx
85
85
where
86
- liftEx :: Aff e a -> Aff (err :: EXCEPTION | e ) a
86
+ liftEx :: Aff e a -> Aff (exception :: EXCEPTION | e ) a
87
87
liftEx = _unsafeInterleaveAff
88
- lowerEx :: Eff (err :: EXCEPTION | e ) (Canceler (err :: EXCEPTION | e )) -> Eff (err :: EXCEPTION | e ) (Canceler e )
88
+ lowerEx :: Eff (exception :: EXCEPTION | e ) (Canceler (exception :: EXCEPTION | e )) -> Eff (exception :: EXCEPTION | e ) (Canceler e )
89
89
lowerEx = map (Canceler <<< map _unsafeInterleaveAff <<< cancel )
90
90
91
91
-- | Runs the asynchronous computation. You must supply an error callback and a
@@ -108,14 +108,9 @@ makeAff h = makeAff' (\e a -> const nonCanceler <$> h e a)
108
108
makeAff' :: forall e a . ((Error -> Eff e Unit ) -> (a -> Eff e Unit ) -> Eff e (Canceler e )) -> Aff e a
109
109
makeAff' h = _makeAff h
110
110
111
- -- | Runs the asynchronous computation off the current execution context.
112
- later :: forall e a . Aff e a -> Aff e a
113
- later = later' 0
114
-
115
- -- | Runs the specified asynchronous computation later, by the specified
116
- -- | number of milliseconds.
117
- later' :: forall e a . Int -> Aff e a -> Aff e a
118
- later' n aff = runFn3 _setTimeout nonCanceler n aff
111
+ -- | Pauses execuation of the current computation for the specified number of milliseconds.
112
+ delay :: forall e . Milliseconds -> Aff e Unit
113
+ delay (Milliseconds n) = runFn2 _delay nonCanceler n
119
114
120
115
-- | Compute `aff1`, followed by `aff2` regardless of whether `aff1` terminated successfully.
121
116
finally :: forall e a b . Aff e a -> Aff e b -> Aff e a
@@ -149,7 +144,7 @@ apathize :: forall e a. Aff e a -> Aff e Unit
149
144
apathize a = const unit <$> attempt a
150
145
151
146
-- | Lifts a synchronous computation and makes explicit any failure from exceptions.
152
- liftEff' :: forall e a . Eff (err :: EXCEPTION | e ) a -> Aff e (Either Error a )
147
+ liftEff' :: forall e a . Eff (exception :: EXCEPTION | e ) a -> Aff e (Either Error a )
153
148
liftEff' eff = attempt (_unsafeInterleaveAff (runFn2 _liftEff nonCanceler eff))
154
149
155
150
-- | A constant canceller that always returns false.
@@ -183,11 +178,14 @@ instance monadAff :: Monad (Aff e)
183
178
instance monadEffAff :: MonadEff e (Aff e ) where
184
179
liftEff eff = runFn2 _liftEff nonCanceler eff
185
180
186
- -- | Allows users to catch and throw errors on the error channel of the
181
+ -- | Allows users to throw errors on the error channel of the
187
182
-- | asynchronous computation. See documentation in `purescript-transformers`.
188
- instance monadErrorAff :: MonadError Error (Aff e ) where
183
+ instance monadThrowAff :: MonadThrow Error (Aff e ) where
189
184
throwError e = runFn2 _throwError nonCanceler e
190
185
186
+ -- | Allows users to catch errors on the error channel of the
187
+ -- | asynchronous computation. See documentation in `purescript-transformers`.
188
+ instance monadErrorAff :: MonadError Error (Aff e ) where
191
189
catchError aff ex = attempt aff >>= either ex pure
192
190
193
191
instance altAff :: Alt (Aff e ) where
@@ -289,7 +287,7 @@ fromAVBox = unsafeCoerce
289
287
290
288
foreign import _cancelWith :: forall e a . Fn3 (Canceler e ) (Aff e a ) (Canceler e ) (Aff e a )
291
289
292
- foreign import _setTimeout :: forall e a . Fn3 (Canceler e ) Int ( Aff e a ) (Aff e a )
290
+ foreign import _delay :: forall e a . Fn2 (Canceler e ) Number (Aff e a )
293
291
294
292
foreign import _unsafeInterleaveAff :: forall e1 e2 a . Aff e1 a -> Aff e2 a
295
293
0 commit comments