Rest
...coros: Coroutine<any>[]The coroutines to wait for
A generator that wait for all of coros
to finish and returns void
import * as coro from '@ajeeb/coroutines'
const downloads = []
function* download(url) {
let done = false
fetch(url)
.then(response => response.json())
.then(data => {
downloads.push(data)
done = true
});
while(!done)
yield
}
const SCHED = new coro.Schedule()
SCHED.add(function() {
yield* coro.all(download('http://example.com/foo.json')
download('http://example.com/bar.json')
download('http://example.com/baz.json'))
console.log(downloads) // will have all downloaded json data at this point
})
setInterval(SCHED.tick, 100)
Returns a coroutine that waits for every coroutine in
coros
to complete.Incomplete
coros
are advanced in order every frame. Cancelling this coroutine with Generator.return forces all remaining coroutines to Generator.return as well, triggering theirfinally
handlers if any.