Skip to content

Commit e187c17

Browse files
committed
add creed task
1 parent 12aa7c7 commit e187c17

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

examples/12-creed.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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!

examples/12-task.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ Task.of(13)
3333
.fork( showErr, showSuc)
3434

3535

36-
const launchMissiles = _ =>
36+
const launchMissilesTask = _ =>
3737
new Task( (rej, res) => {
38-
console.log("launch missile!")
38+
console.log("launch missile from Task!")
3939
res("missile")
4040
})
4141

42-
console.log(`launchMissiles().fork( showErr, showSuc)`)
43-
launchMissiles().fork( showErr, showSuc)
42+
console.log(`launchMissilesTask().fork( showErr, showSuc)`)
43+
launchMissilesTask().fork( showErr, showSuc)
4444

45-
console.log(`launchMissiles().map( x => x + "...FIRE" ).fork( showErr, showSuc)`)
45+
console.log(`launchMissilesTask().map( x => x + "...FIRE" ).fork( showErr, showSuc)`)
4646

47-
launchMissiles()
47+
launchMissilesTask()
4848
.map( x => x + "...FIRE" )
4949

5050
// only this will actually perform the task

0 commit comments

Comments
 (0)