A fast, low-allocation coroutine system with a focus on, but not limited to, games.
The implementation re-uses objects as much a possible using object pooling. The only garbage is generated by creating the IEnumerator when starting the co-routine.
- Fast, single-threaded co-routine scheduler.
- Easy to use and very similar to Unity3D co-routines.
- Co-routines are composable.
IEnumerator SomeRoutine() {
yield return WaitCommand.WaitSeconds(1f);
// Do something
yield return WaitCommand.WaitFrames(5);
// Do something else
// Wait for another co-routine to finish
yield return WaitCommand.WaitRoutine(OtherRoutine());
yield return WaitCommand.WaitForNextFrame;
// Finalize
}
// Create a scheduler and start the co-routine
var scheduler = new CoroutineScheduler();
var routine = scheduler.Run(SomeRoutine());
// Dispose routine to cancel it when it is still running
//routine.Dispose();
void Update() {
// You control the update-rate of the scheduler
scheduler.Update(Time.FrameCount, Time.CurrentTime);
}