Schedules a coroutine for evaluation.
Future calls to Schedule.tick will run coro
up to its next
yield
until it is completed, after which it will be removed from the
schedule.
As a convenience if coro
is a generator function and not a generator,
it will be invoked with no arguments to produce a generator.
Coroutine to add
function* coroutineFunction() { ... }
const SCHED = new Schedule()
SCHED.add(coroutineFunction()) // this works
SCHED.add(coroutineFunction) // so does this
Remove a single coroutine from the schedule.
If coro
is paused in a try
statement this method does not trigger
its finally
handler. If you want logic in the finally
handler to run
you must call Generator.return on coro
yourself.
Coroutine to remove from schedule
function* foo() { ... }
const f = foo()
const SCHED = new Schedule()
SCHED.add(f)
SCHED.tick() // runs foo to next yield
SCHED.remove(f)
SCHED.tick() // foo is not run
Discards all scheduled coroutines.
Similar to Schedule.remove this method does not trigger finally
handlers.
Advances all scheduled coroutines once.
Each coroutine added with Schedule.add is advanced with
Generator.next, causing it to run up to its next yield
statement. Finished coroutines are removed from the schedule.
A coroutine schedule.
Coroutines are added to a schedule with Schedule.add and all scheduled coroutines are advanced with Schedule.tick.
Implemented as an optimized double-ended linked list.