Skip to content

0.11 updates #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"package.json"
],
"dependencies": {
"purescript-console": "^2.0.0",
"purescript-exceptions": "^2.0.0",
"purescript-functions": "^2.0.0",
"purescript-parallel": "^2.0.0",
"purescript-transformers": "^2.0.1",
"purescript-unsafe-coerce": "^2.0.0"
"purescript-console": "^3.0.0",
"purescript-exceptions": "^3.0.0",
"purescript-functions": "^3.0.0",
"purescript-parallel": "^3.0.0",
"purescript-transformers": "^3.0.0",
"purescript-unsafe-coerce": "^3.0.0",
"purescript-datetime": "^3.0.0"
},
"devDependencies": {
"purescript-partial": "^1.1.2"
"purescript-partial": "^1.2.0"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"devDependencies": {
"jscs": "^3.0.7",
"jshint": "^2.9.4",
"pulp": "^10.0.0",
"purescript-psa": "^0.4.0",
"purescript": "^0.10.1",
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.0",
"rimraf": "^2.5.4"
}
}
24 changes: 12 additions & 12 deletions src/Control/Monad/Aff.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ exports._cancelWith = function (nonCanceler, aff, canceler1) {
};
};

exports._setTimeout = function (nonCanceler, millis, aff) {
exports._delay = function (nonCanceler, millis) {
var set = setTimeout;
var clear = clearTimeout;
if (millis <= 0 && typeof setImmediate === "function") {
set = setImmediate;
clear = clearImmediate;
}
return function (success, error) {
var canceler;

var timeout = set(function () {
canceler = aff(success, error);
return function (success) {
var timedOut = false;
var timer = set(function () {
timedOut = true;
success();
}, millis);

return function (e) {
return function (s, f) {
if (canceler !== undefined) {
return canceler(e)(s, f);
return function () {
return function (s) {
if (timedOut) {
s(false);
} else {
clear(timeout);
clear(timer);
s(true);
return nonCanceler;
}
return nonCanceler;
};
};
};
Expand Down
38 changes: 18 additions & 20 deletions src/Control/Monad/Aff.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module Control.Monad.Aff
, finally
, forkAff
, forkAll
, later
, later'
, delay
, launchAff
, liftEff'
, makeAff
Expand All @@ -25,10 +24,10 @@ import Prelude
import Control.Alt (class Alt)
import Control.Alternative (class Alternative)
import Control.Monad.Aff.Internal (AVBox, AVar, _killVar, _putVar, _takeVar, _makeVar)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff (Eff, kind Effect)
import Control.Monad.Eff.Class (class MonadEff)
import Control.Monad.Eff.Exception (Error, EXCEPTION, throwException, error)
import Control.Monad.Error.Class (class MonadError, throwError)
import Control.Monad.Error.Class (class MonadThrow, class MonadError, throwError)
import Control.Monad.Rec.Class (class MonadRec, Step(..))
import Control.MonadPlus (class MonadZero, class MonadPlus)
import Control.Parallel (class Parallel)
Expand All @@ -39,6 +38,7 @@ import Data.Foldable (class Foldable, foldl)
import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3)
import Data.Monoid (class Monoid, mempty)
import Data.Newtype (class Newtype)
import Data.Time.Duration (Milliseconds(..))
import Data.Tuple (Tuple(..), fst, snd)

import Unsafe.Coerce (unsafeCoerce)
Expand All @@ -47,7 +47,7 @@ import Unsafe.Coerce (unsafeCoerce)
-- | errors or produces a value of type `a`.
-- |
-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
foreign import data Aff :: # ! -> * -> *
foreign import data Aff :: # Effect -> Type -> Type

-- | A pure asynchronous computation, having no effects other than
-- | asynchronous computation.
Expand Down Expand Up @@ -80,12 +80,12 @@ cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
-- | If you do need to handle exceptions, you can use `runAff` instead, or
-- | you can handle the exception within the Aff computation, using
-- | `catchError` (or any of the other mechanisms).
launchAff :: forall e a. Aff e a -> Eff (err :: EXCEPTION | e) (Canceler e)
launchAff :: forall e a. Aff e a -> Eff (exception :: EXCEPTION | e) (Canceler e)
launchAff = lowerEx <<< runAff throwException (const (pure unit)) <<< liftEx
where
liftEx :: Aff e a -> Aff (err :: EXCEPTION | e) a
liftEx :: Aff e a -> Aff (exception :: EXCEPTION | e) a
liftEx = _unsafeInterleaveAff
lowerEx :: Eff (err :: EXCEPTION | e) (Canceler (err :: EXCEPTION | e)) -> Eff (err :: EXCEPTION | e) (Canceler e)
lowerEx :: Eff (exception :: EXCEPTION | e) (Canceler (exception :: EXCEPTION | e)) -> Eff (exception :: EXCEPTION | e) (Canceler e)
lowerEx = map (Canceler <<< map _unsafeInterleaveAff <<< cancel)

-- | Runs the asynchronous computation. You must supply an error callback and a
Expand All @@ -108,14 +108,9 @@ makeAff h = makeAff' (\e a -> const nonCanceler <$> h e a)
makeAff' :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e (Canceler e)) -> Aff e a
makeAff' h = _makeAff h

-- | Runs the asynchronous computation off the current execution context.
later :: forall e a. Aff e a -> Aff e a
later = later' 0

-- | Runs the specified asynchronous computation later, by the specified
-- | number of milliseconds.
later' :: forall e a. Int -> Aff e a -> Aff e a
later' n aff = runFn3 _setTimeout nonCanceler n aff
-- | Pauses execuation of the current computation for the specified number of milliseconds.
delay :: forall e. Milliseconds -> Aff e Unit
delay (Milliseconds n) = runFn2 _delay nonCanceler n

-- | Compute `aff1`, followed by `aff2` regardless of whether `aff1` terminated successfully.
finally :: forall e a b. Aff e a -> Aff e b -> Aff e a
Expand Down Expand Up @@ -149,7 +144,7 @@ apathize :: forall e a. Aff e a -> Aff e Unit
apathize a = const unit <$> attempt a

-- | Lifts a synchronous computation and makes explicit any failure from exceptions.
liftEff' :: forall e a. Eff (err :: EXCEPTION | e) a -> Aff e (Either Error a)
liftEff' :: forall e a. Eff (exception :: EXCEPTION | e) a -> Aff e (Either Error a)
liftEff' eff = attempt (_unsafeInterleaveAff (runFn2 _liftEff nonCanceler eff))

-- | A constant canceller that always returns false.
Expand Down Expand Up @@ -183,11 +178,14 @@ instance monadAff :: Monad (Aff e)
instance monadEffAff :: MonadEff e (Aff e) where
liftEff eff = runFn2 _liftEff nonCanceler eff

-- | Allows users to catch and throw errors on the error channel of the
-- | Allows users to throw errors on the error channel of the
-- | asynchronous computation. See documentation in `purescript-transformers`.
instance monadErrorAff :: MonadError Error (Aff e) where
instance monadThrowAff :: MonadThrow Error (Aff e) where
throwError e = runFn2 _throwError nonCanceler e

-- | Allows users to catch errors on the error channel of the
-- | asynchronous computation. See documentation in `purescript-transformers`.
instance monadErrorAff :: MonadError Error (Aff e) where
catchError aff ex = attempt aff >>= either ex pure

instance altAff :: Alt (Aff e) where
Expand Down Expand Up @@ -289,7 +287,7 @@ fromAVBox = unsafeCoerce

foreign import _cancelWith :: forall e a. Fn3 (Canceler e) (Aff e a) (Canceler e) (Aff e a)

foreign import _setTimeout :: forall e a. Fn3 (Canceler e) Int (Aff e a) (Aff e a)
foreign import _delay :: forall e a. Fn2 (Canceler e) Number (Aff e a)

foreign import _unsafeInterleaveAff :: forall e1 e2 a. Aff e1 a -> Aff e2 a

Expand Down
3 changes: 2 additions & 1 deletion src/Control/Monad/Aff/AVar.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import Prelude
import Control.Monad.Aff (Aff, nonCanceler)
import Control.Monad.Aff.Internal (AVar) as Exports
import Control.Monad.Aff.Internal (AVBox, AVar, _killVar, _putVar, _takeVar, _peekVar, _makeVar)
import Control.Monad.Eff (kind Effect)
import Control.Monad.Eff.Exception (Error())

import Data.Function.Uncurried (runFn3, runFn2)

import Unsafe.Coerce (unsafeCoerce)

foreign import data AVAR :: !
foreign import data AVAR :: Effect

type AffAVar e a = Aff (avar :: AVAR | e) a

Expand Down
4 changes: 2 additions & 2 deletions src/Control/Monad/Aff/Internal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import Control.Monad.Eff.Exception (Error)

import Data.Function.Uncurried (Fn2, Fn3)

foreign import data AVar :: * -> *
foreign import data AVar :: Type -> Type

foreign import data AVBox :: * -> *
foreign import data AVBox :: Type -> Type

foreign import _makeVar :: forall c a. c -> AVBox (AVar a)

Expand Down
Loading