File tree Expand file tree Collapse file tree 2 files changed +48
-6
lines changed Expand file tree Collapse file tree 2 files changed +48
-6
lines changed Original file line number Diff line number Diff line change
1
+ const { Promise : CreedPromise } = require ( 'creed' )
2
+
3
+ const launchMissilesCreed = _ =>
4
+ new CreedPromise ( res => {
5
+ console . log ( "launch missile from Creed!" )
6
+ res ( "missile" )
7
+ } )
8
+
9
+ const launchMissilesPromise = _ =>
10
+ new Promise ( res => {
11
+ console . log ( "launch missile from Promise!" )
12
+ res ( "missile" )
13
+ } )
14
+
15
+ launchMissilesCreed ( )
16
+ . map ( x => x + "...FIRE" )
17
+ . map ( console . log )
18
+
19
+ launchMissilesPromise ( )
20
+ . then ( x => x + "...FIRE" )
21
+ . then ( console . log )
22
+
23
+
24
+
25
+ const suspendedLaunchCreed = _ =>
26
+ // return suspended missile inside function,
27
+ CreedPromise . of ( { then : _ => {
28
+ console . log ( "Creed missile is launched!!!" )
29
+ } } )
30
+
31
+ const suspendedLaunchPromise = _ =>
32
+ // return suspended missile inside function,
33
+ Promise . resolve ( { then : _ => {
34
+ console . log ( "Promise missile is launched!!!" )
35
+ } } )
36
+
37
+ suspendedLaunchCreed ( )
38
+ // execute instruction
39
+ . then ( instruction => instruction . then ( ) )
40
+
41
+ suspendedLaunchPromise ( )
42
+ // missiled is launched by itself -- danger!
Original file line number Diff line number Diff line change @@ -33,18 +33,18 @@ Task.of(13)
33
33
. fork ( showErr , showSuc )
34
34
35
35
36
- const launchMissiles = _ =>
36
+ const launchMissilesTask = _ =>
37
37
new Task ( ( rej , res ) => {
38
- console . log ( "launch missile!" )
38
+ console . log ( "launch missile from Task !" )
39
39
res ( "missile" )
40
40
} )
41
41
42
- console . log ( `launchMissiles ().fork( showErr, showSuc)` )
43
- launchMissiles ( ) . fork ( showErr , showSuc )
42
+ console . log ( `launchMissilesTask ().fork( showErr, showSuc)` )
43
+ launchMissilesTask ( ) . fork ( showErr , showSuc )
44
44
45
- console . log ( `launchMissiles ().map( x => x + "...FIRE" ).fork( showErr, showSuc)` )
45
+ console . log ( `launchMissilesTask ().map( x => x + "...FIRE" ).fork( showErr, showSuc)` )
46
46
47
- launchMissiles ( )
47
+ launchMissilesTask ( )
48
48
. map ( x => x + "...FIRE" )
49
49
50
50
// only this will actually perform the task
You can’t perform that action at this time.
0 commit comments