Intentando hacer algo similar a https://doc.babylonjs.com/divingDeeper/events/coroutines de Babylon.js
const spawnMeshesCoroutine = function* () { spawnTheFirstMesh(); yield; spawnTheSecondMesh(); yield; spawnTheThirdMesh(); }; scene.onBeforeRenderObservable.runCoroutineAsync(spawnMeshesCoroutine());Pero me pregunto si hay ejemplos simples de JS para ejecutar una rutina más simple que pueda manejar algunas tareas costosas en JS sin bloquear la interfaz de usuario.
Un experimento con "tareas costosas": buscando soluciones para habilitar la interfaz de usuario de sugerencia automática de 60 fps sin bloqueo para reaccionar
Una forma de ejecutar una función en múltiples bucles de eventos es:
async function spawnFirstMeshAsync() { return spawnFirstMesh(); } async function spawnSecondMeshAsync() { return spawnSecondMesh(); } async function spawnThirdMeshAsync() { return spawnThirdMesh(); } async function spawnMeshes() { await spawnFirstMesh(); await spawnSecondMesh(); await spawnThirdMesh(); } En términos de sincronización con marcos como lo hace Babylon.js, consulte requestAnimationFrame .