Trying to do something similar to Babylon.js's https://doc.babylonjs.com/divingDeeper/events/coroutines
const spawnMeshesCoroutine = function* () {
spawnTheFirstMesh();
yield;
spawnTheSecondMesh();
yield;
spawnTheThirdMesh();
};
scene.onBeforeRenderObservable.runCoroutineAsync(spawnMeshesCoroutine());
But wondering if there are any simple JS examples to run a simpler coroutine that may handle some expensive tasks in JS without blocking the UI.
An experiment with "expensive tasks": Looking for solutions to enable non-blocking 60fps autosuggest UI for react
A way to run a function across multiple event loops is:
async function spawnFirstMeshAsync() {
return spawnFirstMesh();
}
async function spawnSecondMeshAsync() {
return spawnSecondMesh();
}
async function spawnThirdMeshAsync() {
return spawnThirdMesh();
}
async function spawnMeshes() {
await spawnFirstMesh();
await spawnSecondMesh();
await spawnThirdMesh();
}
In terms of synchronizing with frames as Babylon.js does, look into requestAnimationFrame.