Coroutine system based on ES6 Generators and inspired by the coroutines in the Unity 3D game engine.
This module provides a Schedule which contains contains coroutines, advances them, and removes them when they are complete, and a few utility coroutines that are generally helpful.
import * as coro from '@ajeeb/coroutines'
const SCHED = new coro.Schedule()
// function* literals are supported
SCHED.add(function* main() {
// ...
})
// call `tick` to advance all scheduled coroutines
// calling `tick` once per frame means each tick is one frame and each yield
// means "wait one frame"
function tick() {
SCHED.tick()
requestAnimationFrame(tick)
}
tick()