Skip to content

Instantly share code, notes, and snippets.

@jahan-addison
Created September 30, 2015 01:23
Show Gist options
  • Save jahan-addison/60e9293f6606bf9ae7d0 to your computer and use it in GitHub Desktop.
Save jahan-addison/60e9293f6606bf9ae7d0 to your computer and use it in GitHub Desktop.
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