• 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 their finally handlers if any.

    Parameters

    • Rest ...coros: Coroutine<any>[]

      The coroutines to wait for

    Returns Generator<any, void, unknown>

    A generator that wait for all of coros to finish and returns void

    See

    Generator.return

    Example: Wait for downloads

    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)