Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const after = (n, x) => Future((l, r) => setTimeout(r, n, x));
const Do = (f, of) => {
return of(undefined).chain(() => {
const g = f()
const step = value => {
const result = g.next(value)
return result.done ?
of(result.value) :
result.value.chain(step)
}
return step()
})
}
const fut = Do(function*(){
const a = yield after(300, 1);
const b = yield after(300, 2);
return a + b;
}, Future.of);
fut.fork(console.log, console.log)
fut.fork(console.log, console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment