0.0.2 • Published 7 years ago

tiny-co v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

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)
    })
  }
}