Skip to content

Commit 1485978

Browse files
authored
Merge pull request #92 from natefaubion/0.11-updates
0.11 updates
2 parents eddf851 + 7110bb7 commit 1485978

File tree

7 files changed

+104
-100
lines changed

7 files changed

+104
-100
lines changed

bower.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-console": "^2.0.0",
21-
"purescript-exceptions": "^2.0.0",
22-
"purescript-functions": "^2.0.0",
23-
"purescript-parallel": "^2.0.0",
24-
"purescript-transformers": "^2.0.1",
25-
"purescript-unsafe-coerce": "^2.0.0"
20+
"purescript-console": "^3.0.0",
21+
"purescript-exceptions": "^3.0.0",
22+
"purescript-functions": "^3.0.0",
23+
"purescript-parallel": "^3.0.0",
24+
"purescript-transformers": "^3.0.0",
25+
"purescript-unsafe-coerce": "^3.0.0",
26+
"purescript-datetime": "^3.0.0"
2627
},
2728
"devDependencies": {
28-
"purescript-partial": "^1.1.2"
29+
"purescript-partial": "^1.2.0"
2930
}
3031
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"devDependencies": {
99
"jscs": "^3.0.7",
1010
"jshint": "^2.9.4",
11-
"pulp": "^10.0.0",
12-
"purescript-psa": "^0.4.0",
13-
"purescript": "^0.10.1",
11+
"pulp": "^11.0.0",
12+
"purescript-psa": "^0.5.0",
13+
"purescript": "^0.11.0",
1414
"rimraf": "^2.5.4"
1515
}
1616
}

src/Control/Monad/Aff.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,29 @@ exports._cancelWith = function (nonCanceler, aff, canceler1) {
3636
};
3737
};
3838

39-
exports._setTimeout = function (nonCanceler, millis, aff) {
39+
exports._delay = function (nonCanceler, millis) {
4040
var set = setTimeout;
4141
var clear = clearTimeout;
4242
if (millis <= 0 && typeof setImmediate === "function") {
4343
set = setImmediate;
4444
clear = clearImmediate;
4545
}
46-
return function (success, error) {
47-
var canceler;
48-
49-
var timeout = set(function () {
50-
canceler = aff(success, error);
46+
return function (success) {
47+
var timedOut = false;
48+
var timer = set(function () {
49+
timedOut = true;
50+
success();
5151
}, millis);
5252

53-
return function (e) {
54-
return function (s, f) {
55-
if (canceler !== undefined) {
56-
return canceler(e)(s, f);
53+
return function () {
54+
return function (s) {
55+
if (timedOut) {
56+
s(false);
5757
} else {
58-
clear(timeout);
58+
clear(timer);
5959
s(true);
60-
return nonCanceler;
6160
}
61+
return nonCanceler;
6262
};
6363
};
6464
};

src/Control/Monad/Aff.purs

+18-20
Original file line numberDiff line numberDiff line change
@@ -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
2524
import Control.Alt (class Alt)
2625
import Control.Alternative (class Alternative)
2726
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)
2928
import Control.Monad.Eff.Class (class MonadEff)
3029
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)
3231
import Control.Monad.Rec.Class (class MonadRec, Step(..))
3332
import Control.MonadPlus (class MonadZero, class MonadPlus)
3433
import Control.Parallel (class Parallel)
@@ -39,6 +38,7 @@ import Data.Foldable (class Foldable, foldl)
3938
import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3)
4039
import Data.Monoid (class Monoid, mempty)
4140
import Data.Newtype (class Newtype)
41+
import Data.Time.Duration (Milliseconds(..))
4242
import Data.Tuple (Tuple(..), fst, snd)
4343

4444
import 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)
8484
launchAff = 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)
108108
makeAff' :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e (Canceler e)) -> Aff e a
109109
makeAff' 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.
121116
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
149144
apathize 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)
153148
liftEff' 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)
183178
instance 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

193191
instance altAff :: Alt (Aff e) where
@@ -289,7 +287,7 @@ fromAVBox = unsafeCoerce
289287

290288
foreign 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

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

src/Control/Monad/Aff/AVar.purs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import Prelude
1717
import Control.Monad.Aff (Aff, nonCanceler)
1818
import Control.Monad.Aff.Internal (AVar) as Exports
1919
import Control.Monad.Aff.Internal (AVBox, AVar, _killVar, _putVar, _takeVar, _peekVar, _makeVar)
20+
import Control.Monad.Eff (kind Effect)
2021
import Control.Monad.Eff.Exception (Error())
2122

2223
import Data.Function.Uncurried (runFn3, runFn2)
2324

2425
import Unsafe.Coerce (unsafeCoerce)
2526

26-
foreign import data AVAR :: !
27+
foreign import data AVAR :: Effect
2728

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

src/Control/Monad/Aff/Internal.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import Control.Monad.Eff.Exception (Error)
1414

1515
import Data.Function.Uncurried (Fn2, Fn3)
1616

17-
foreign import data AVar :: * -> *
17+
foreign import data AVar :: Type -> Type
1818

19-
foreign import data AVBox :: * -> *
19+
foreign import data AVBox :: Type -> Type
2020

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

0 commit comments

Comments
 (0)