Skip to content

Asynchronous Generators, Iterators, and Iteration Function

Notifications You must be signed in to change notification settings

DanielHerr/Async-Iteration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Async-Iteration

Asynchronous Generators, Iterators, and Iteration Function

Polyfill for async generators and iterators, with yield functioning as await when called on promises, and forasync() replacing forawait of.

Usage:

var test = asyncgen(function*() {
 yield(Promise.resolve())
 yield(2)
 yield(4)
 yield(6)
})

var asynciterator = test()
asynciterator.next().then(function({ done, value }) {
 console.log(done, value) // false, 2
})

forasync(test(), async function(value, stop, iteration = 1, original) {
 console.log(value, iteration) // 2, 1 // 4, 2
 if(value == 4 && iteration == 2) {
  return(stop(value))
} }).then(function(results = []) {
 console.log(results) // [ undefined, 4 ]
})

Run Tests

About

Asynchronous Generators, Iterators, and Iteration Function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published