tiny-co
v0.0.2
Published
a control flow for js generator function.
Downloads
3
Maintainers
Readme
tiny-co
One Generator control flow absort idea from tj/co
miletone
next()
of Generator function should be call in sync code.
if do it in callback, maybe cause unexpected situation:
function co (gen) {
const g = gen()
const p = new Promise(resolve => { resolve() })
let next = {value: p, done: false}
let n = 0
while (!next.done) {
next.value.then(data => {
// bug, next in here will never affect while judgement.
next = g.next(data)
})
}
}