@@ -9,8 +9,7 @@ module Control.Monad.Aff
99 , finally
1010 , forkAff
1111 , forkAll
12- , later
13- , later'
12+ , delay
1413 , launchAff
1514 , liftEff'
1615 , makeAff
@@ -25,10 +24,10 @@ import Prelude
2524import Control.Alt (class Alt )
2625import Control.Alternative (class Alternative )
2726import Control.Monad.Aff.Internal (AVBox , AVar , _killVar , _putVar , _takeVar , _makeVar )
28- import Control.Monad.Eff (Eff )
27+ import Control.Monad.Eff (Eff , kind Effect )
2928import Control.Monad.Eff.Class (class MonadEff )
3029import 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 )
3231import Control.Monad.Rec.Class (class MonadRec , Step (..))
3332import Control.MonadPlus (class MonadZero , class MonadPlus )
3433import Control.Parallel (class Parallel )
@@ -39,6 +38,7 @@ import Data.Foldable (class Foldable, foldl)
3938import Data.Function.Uncurried (Fn2 , Fn3 , runFn2 , runFn3 )
4039import Data.Monoid (class Monoid , mempty )
4140import Data.Newtype (class Newtype )
41+ import Data.Time.Duration (Milliseconds (..))
4242import Data.Tuple (Tuple (..), fst , snd )
4343
4444import Unsafe.Coerce (unsafeCoerce )
@@ -47,7 +47,7 @@ import Unsafe.Coerce (unsafeCoerce)
4747-- | errors or produces a value of type `a`.
4848-- |
4949-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
50- foreign import data Aff :: # ! -> * -> *
50+ foreign import data Aff :: # Effect -> Type -> Type
5151
5252-- | A pure asynchronous computation, having no effects other than
5353-- | asynchronous computation.
@@ -80,12 +80,12 @@ cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
8080-- | If you do need to handle exceptions, you can use `runAff` instead, or
8181-- | you can handle the exception within the Aff computation, using
8282-- | `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 )
8484launchAff = lowerEx <<< runAff throwException (const (pure unit)) <<< liftEx
8585 where
86- liftEx :: Aff e a -> Aff (err :: EXCEPTION | e ) a
86+ liftEx :: Aff e a -> Aff (exception :: EXCEPTION | e ) a
8787 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 )
8989 lowerEx = map (Canceler <<< map _unsafeInterleaveAff <<< cancel )
9090
9191-- | 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)
108108makeAff' :: forall e a . ((Error -> Eff e Unit ) -> (a -> Eff e Unit ) -> Eff e (Canceler e )) -> Aff e a
109109makeAff' h = _makeAff h
110110
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
119114
120115-- | Compute `aff1`, followed by `aff2` regardless of whether `aff1` terminated successfully.
121116finally :: 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
149144apathize a = const unit <$> attempt a
150145
151146-- | 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 )
153148liftEff' eff = attempt (_unsafeInterleaveAff (runFn2 _liftEff nonCanceler eff))
154149
155150-- | A constant canceller that always returns false.
@@ -183,11 +178,14 @@ instance monadAff :: Monad (Aff e)
183178instance monadEffAff :: MonadEff e (Aff e ) where
184179 liftEff eff = runFn2 _liftEff nonCanceler eff
185180
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
187182-- | asynchronous computation. See documentation in `purescript-transformers`.
188- instance monadErrorAff :: MonadError Error (Aff e ) where
183+ instance monadThrowAff :: MonadThrow Error (Aff e ) where
189184 throwError e = runFn2 _throwError nonCanceler e
190185
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
191189 catchError aff ex = attempt aff >>= either ex pure
192190
193191instance altAff :: Alt (Aff e ) where
@@ -289,7 +287,7 @@ fromAVBox = unsafeCoerce
289287
290288foreign import _cancelWith :: forall e a . Fn3 (Canceler e ) (Aff e a ) (Canceler e ) (Aff e a )
291289
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 )
293291
294292foreign import _unsafeInterleaveAff :: forall e1 e2 a . Aff e1 a -> Aff e2 a
295293
0 commit comments