Closed eonarheim closed 1 month ago
===:clipboard: PR Checklist :clipboard:===
==================
This PR gives users greater flexibility with Excalibur Coroutines!
Optionally ask coroutines not to start immediately
ex.coroutine(function* () { .. }, { autostart: false });
New CoroutineInstance is returned that is also awaitable
CoroutineInstance
export interface CoroutineOptions { timing?: ScheduledCallbackTiming; autostart?: boolean; } export interface CoroutineInstance extends PromiseLike<void> { isRunning(): boolean; isComplete(): boolean; done: Promise<void>; generator: Generator<CoroutineInstance | number | Promise<any> | undefined, void, number>; start: () => CoroutineInstance; cancel: () => void; then: Thenable; [Symbol.iterator]: () => Generator<CoroutineInstance | number | Promise<any> | undefined, void, number>; }
const co = ex.coroutine(function* () { yield 100; }); await co; // wait for coroutine to finish
start()/cancel()coroutines
start()
cancel()
const co = ex.coroutine(function* () { yield 100; }); co.start(); co.cancel(); await co;
nested coroutines! (Nested coroutines do not start running, they are run with their parent)
const result = ex.coroutine(function* () { yield 100; yield* ex.coroutine(function* () { const elapsed = yield 99; }); yield 100; });
bbf5e3a
View logs
===:clipboard: PR Checklist :clipboard:===
==================
This PR gives users greater flexibility with Excalibur Coroutines!
Optionally ask coroutines not to start immediately
New
CoroutineInstance
is returned that is also awaitablestart()
/cancel()
coroutinesnested coroutines! (Nested coroutines do not start running, they are run with their parent)