Skip to content

Instantly share code, notes, and snippets.

@Avaq
Created April 5, 2017 11:51
Show Gist options
  • Save Avaq/3128647d86abef4d1284d4de456ab829 to your computer and use it in GitHub Desktop.
Save Avaq/3128647d86abef4d1284d4de456ab829 to your computer and use it in GitHub Desktop.
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