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
43
43
liftEff $ trace (show n ++ " seconds left ")
44
44
test_sequencing (n - 1)
45
45
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
+
46
53
test_attempt :: Test
47
54
test_attempt = do
48
55
e <- attempt (throwError (error "Oh noes!"))
@@ -73,11 +80,13 @@ module Examples where
73
80
Par (timeout 1000 *> pure "Failure: Late bird got the worm"))
74
81
liftEff $ trace s
75
82
76
-
77
83
main = launchAff $ do
78
84
liftEff $ trace " Testing sequencing"
79
85
test_sequencing 3
80
86
87
+ liftEff $ trace " Testing pure"
88
+ test_pure
89
+
81
90
liftEff $ trace " Testing attempt"
82
91
test_attempt
83
92
Original file line number Diff line number Diff line change @@ -23,11 +23,6 @@ module Control.Monad.Aff.Par
23
23
runPar :: forall e a. Par e a -> AffVar e a
24
24
runPar (Par aff ) = aff
25
25
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
-
31
26
instance semigroupPar :: (Semigroup a ) => Semigroup (Par e a ) where
32
27
(<>) a b = (<>) <$> a <*> b
33
28
@@ -48,6 +43,7 @@ module Control.Monad.Aff.Par
48
43
instance applicativePar :: Applicative (Par e ) where
49
44
pure v = Par (pure v )
50
45
46
+ -- | Returns the first value, or the first error if both error.
51
47
instance altPar :: Alt (Par e ) where
52
48
(<|>) (Par a1 ) (Par a2 ) =
53
49
let maybeKill va ve err =
Original file line number Diff line number Diff line change 1
1
module Control.Monad.Aff.Unsafe where
2
2
import Control.Monad.Aff
3
3
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
+
4
18
foreign import unsafeInterleaveAff " " "
5
19
function unsafeInterleaveAff(aff) {
6
20
return aff;
Original file line number Diff line number Diff line change @@ -71,15 +71,14 @@ module Control.Monad.Aff.Var
71
71
return function(error) {
72
72
return function(success) {
73
73
return function() {
74
- console.log(" putting " + a + " into var: " );
75
- console.log(avar);
76
-
77
74
if (avar.error !== undefined) {
78
75
error(avar.error)();
79
- } else if (avar.consumers.length == 0) {
76
+ } else if (avar.consumers.length === 0) {
80
77
avar.producers.push(function(error, success) {
81
78
success(a)();
82
79
});
80
+
81
+ success({})();
83
82
} else {
84
83
var consumer = avar.consumers.shift();
85
84
You can’t perform that action at this time.
0 commit comments