File tree Expand file tree Collapse file tree 5 files changed +60
-24
lines changed Expand file tree Collapse file tree 5 files changed +60
-24
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ module Examples where
4343 liftEff $ trace (show n ++ " seconds left ")
4444 test_sequencing (n - 1)
4545
46+ test_pure :: Test
47+ test_pure = do
48+ pure unit
49+ pure unit
50+ pure unit
51+ liftEff $ trace " Success: Got all the way past 4 pures"
52+
4653 test_attempt :: Test
4754 test_attempt = do
4855 e <- attempt (throwError (error "Oh noes!"))
@@ -73,11 +80,13 @@ module Examples where
7380 Par (timeout 1000 *> pure "Failure: Late bird got the worm"))
7481 liftEff $ trace s
7582
76-
7783 main = launchAff $ do
7884 liftEff $ trace " Testing sequencing"
7985 test_sequencing 3
8086
87+ liftEff $ trace " Testing pure"
88+ test_pure
89+
8190 liftEff $ trace " Testing attempt"
8291 test_attempt
8392
Original file line number Diff line number Diff line change @@ -23,11 +23,6 @@ module Control.Monad.Aff.Par
2323 runPar :: forall e a. Par e a -> AffVar e a
2424 runPar (Par aff ) = aff
2525
26- -- | Races two parallel computations for the one that finishes first.
27- -- | A synonym for (<|>).
28- race :: forall e a. Par e a -> Par e a -> Par e a
29- race p1 p2 = p1 <|> p2
30-
3126 instance semigroupPar :: (Semigroup a ) => Semigroup (Par e a ) where
3227 (<>) a b = (<>) <$> a <*> b
3328
@@ -48,6 +43,7 @@ module Control.Monad.Aff.Par
4843 instance applicativePar :: Applicative (Par e ) where
4944 pure v = Par (pure v )
5045
46+ -- | Returns the first value, or the first error if both error.
5147 instance altPar :: Alt (Par e ) where
5248 (<|>) (Par a1 ) (Par a2 ) =
5349 let maybeKill va ve err =
Original file line number Diff line number Diff line change 11module Control.Monad.Aff.Unsafe where
22 import Control.Monad.Aff
33
4+ foreign import unsafeTrace " " "
5+ function unsafeTrace(v) {
6+ return function(error) {
7+ return function(success) {
8+ return function() {
9+ console.log(v);
10+
11+ success({})();
12+ }
13+ }
14+ }
15+ }
16+ " " " :: forall e a. a -> Aff e Unit
17+
418 foreign import unsafeInterleaveAff " " "
519 function unsafeInterleaveAff(aff) {
620 return aff;
Original file line number Diff line number Diff line change @@ -71,15 +71,14 @@ module Control.Monad.Aff.Var
7171 return function(error) {
7272 return function(success) {
7373 return function() {
74- console.log(" putting " + a + " into var: " );
75- console.log(avar);
76-
7774 if (avar.error !== undefined) {
7875 error(avar.error)();
79- } else if (avar.consumers.length == 0) {
76+ } else if (avar.consumers.length === 0) {
8077 avar.producers.push(function(error, success) {
8178 success(a)();
8279 });
80+
81+ success({})();
8382 } else {
8483 var consumer = avar.consumers.shift();
8584
You can’t perform that action at this time.
0 commit comments