Created
September 30, 2015 01:23
-
-
Save jahan-addison/60e9293f6606bf9ae7d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assert from 'assert'; | |
import co from 'co'; | |
const state1 = (_) => new Promise((resolve, reject) => { | |
resolve(5); | |
}); | |
const state2 = (a) => new Promise((resolve, reject) => { | |
resolve(a + 5); | |
}); | |
const state3 = (b) => new Promise((resolve, reject) => { | |
resolve(b + 5); | |
}); | |
const error = e => console.log(e.stack); | |
co(function *() { | |
let _; | |
let states = [state1, state2, state3]; | |
assert.equal(_ = yield states.shift()(_), 5); | |
assert.equal(_ = yield states.shift()(_), 10); | |
assert.equal(_ = yield states.shift()(_), 15); | |
}).catch(error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment