1 |
- {"ast":null,"code":"/* eslint-disable @typescript-eslint/naming-convention */\n// \"Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed.\"\n// https://en.wikipedia.org/wiki/Coroutine\n// The inline scheduler simply steps the coroutine synchronously. This is useful for running a coroutine synchronously, and also as a helper function for other schedulers.\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function inlineScheduler(coroutine, onStep, onError) {\n try {\n const step = coroutine.next();\n if (step.done) {\n onStep(step);\n } else if (!step.value) {\n // NOTE: The properties of step have been narrowed, but the type of step itself is not narrowed, so the cast below is the most type safe way to deal with this without instantiating a new object to hold the values.\n onStep(step);\n } else {\n step.value.then(() => {\n step.value = undefined;\n onStep(step);\n }, onError);\n }\n } catch (error) {\n onError(error);\n }\n}\n// The yielding scheduler steps the coroutine synchronously until the specified time interval has elapsed, then yields control so other operations can be performed.\n// A single instance of a yielding scheduler could be shared across multiple coroutines to yield when their collective work exceeds the threshold.\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function createYieldingScheduler(yieldAfterMS = 25) {\n let startTime;\n return (coroutine, onStep, onError) => {\n const currentTime = performance.now();\n if (startTime === undefined || currentTime - startTime > yieldAfterMS) {\n // If this is the first coroutine step, or if the time interval has elapsed, record a new start time, and schedule the coroutine step to happen later, effectively yielding control of the execution context.\n startTime = currentTime;\n setTimeout(() => {\n inlineScheduler(coroutine, onStep, onError);\n }, 0);\n } else {\n // Otherwise it is not time to yield yet, so step the coroutine synchronously.\n inlineScheduler(coroutine, onStep, onError);\n }\n };\n}\n// Runs the specified coroutine with the specified scheduler. The success or error callback will be invoked when the coroutine finishes.\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function runCoroutine(coroutine, scheduler, onSuccess, onError, abortSignal) {\n const resume = () => {\n let reschedule;\n const onStep = stepResult => {\n if (stepResult.done) {\n // If the coroutine is done, report success.\n onSuccess(stepResult.value);\n } else {\n // If the coroutine is not done, resume the coroutine (via the scheduler).\n if (reschedule === undefined) {\n // If reschedule is undefined at this point, then the coroutine must have stepped synchronously, so just flag another loop iteration.\n reschedule = true;\n } else {\n // If reschedule is defined at this point, then the coroutine must have stepped asynchronously, so call resume to restart the step loop.\n resume();\n }\n }\n };\n do {\n reschedule = undefined;\n if (!abortSignal || !abortSignal.aborted) {\n scheduler(coroutine, onStep, onError);\n } else {\n onError(new Error(\"Aborted\"));\n }\n if (reschedule === undefined) {\n // If reschedule is undefined at this point, then the coroutine must have stepped asynchronously, so stop looping and let the coroutine be resumed later.\n reschedule = false;\n }\n } while (reschedule);\n };\n resume();\n}\n// Runs the specified coroutine synchronously.\n/**\n * @internal\n */\nexport function runCoroutineSync(coroutine, abortSignal) {\n // Run the coroutine with the inline scheduler, storing the returned value, or re-throwing the error (since the error callback will be called synchronously by the inline scheduler).\n let result;\n runCoroutine(coroutine, inlineScheduler, r => result = r, e => {\n throw e;\n }, abortSignal);\n // Synchronously return the result of the coroutine.\n return result;\n}\n// Runs the specified coroutine asynchronously with the specified scheduler.\n/**\n * @internal\n */\nexport function runCoroutineAsync(coroutine, scheduler, abortSignal) {\n // Run the coroutine with a yielding scheduler, resolving or rejecting the result promise when the coroutine finishes.\n return new Promise((resolve, reject) => {\n runCoroutine(coroutine, scheduler, resolve, reject, abortSignal);\n });\n}\n/**\n * Given a function that returns a Coroutine<T>, produce a function with the same parameters that returns a T.\n * The returned function runs the coroutine synchronously.\n * @param coroutineFactory A function that returns a Coroutine<T>.\n * @param abortSignal\n * @returns A function that runs the coroutine synchronously.\n * @internal\n */\nexport function makeSyncFunction(coroutineFactory, abortSignal) {\n return (...params) => {\n // Run the coroutine synchronously.\n return runCoroutineSync(coroutineFactory(...params), abortSignal);\n };\n}\n/**\n * Given a function that returns a Coroutine<T>, product a function with the same parameters that returns a Promise<T>.\n * The returned function runs the coroutine asynchronously, yield control of the execution context occasionally to enable a more responsive experience.\n * @param coroutineFactory A function that returns a Coroutine<T>.\n * @param scheduler\n * @param abortSignal\n * @returns A function that runs the coroutine asynchronously.\n * @internal\n */\nexport function makeAsyncFunction(coroutineFactory, scheduler, abortSignal) {\n return (...params) => {\n // Run the coroutine asynchronously.\n return runCoroutineAsync(coroutineFactory(...params), scheduler, abortSignal);\n };\n}","map":{"version":3,"names":["inlineScheduler","coroutine","onStep","onError","step","next","done","value","then","undefined","error","createYieldingScheduler","yieldAfterMS","startTime","currentTime","performance","now","setTimeout","runCoroutine","scheduler","onSuccess","abortSignal","resume","reschedule","stepResult","aborted","Error","runCoroutineSync","result","r","e","runCoroutineAsync","Promise","resolve","reject","makeSyncFunction","coroutineFactory","params","makeAsyncFunction"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Misc/coroutine.js"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n// \"Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed.\"\n// https://en.wikipedia.org/wiki/Coroutine\n// The inline scheduler simply steps the coroutine synchronously. This is useful for running a coroutine synchronously, and also as a helper function for other schedulers.\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function inlineScheduler(coroutine, onStep, onError) {\n try {\n const step = coroutine.next();\n if (step.done) {\n onStep(step);\n }\n else if (!step.value) {\n // NOTE: The properties of step have been narrowed, but the type of step itself is not narrowed, so the cast below is the most type safe way to deal with this without instantiating a new object to hold the values.\n onStep(step);\n }\n else {\n step.value.then(() => {\n step.value = undefined;\n onStep(step);\n }, onError);\n }\n }\n catch (error) {\n onError(error);\n }\n}\n// The yielding scheduler steps the coroutine synchronously until the specified time interval has elapsed, then yields control so other operations can be performed.\n// A single instance of a yielding scheduler could be shared across multiple coroutines to yield when their collective work exceeds the threshold.\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function createYieldingScheduler(yieldAfterMS = 25) {\n let startTime;\n return (coroutine, onStep, onError) => {\n const currentTime = performance.now();\n if (startTime === undefined || currentTime - startTime > yieldAfterMS) {\n // If this is the first coroutine step, or if the time interval has elapsed, record a new start time, and schedule the coroutine step to happen later, effectively yielding control of the execution context.\n startTime = currentTime;\n setTimeout(() => {\n inlineScheduler(coroutine, onStep, onError);\n }, 0);\n }\n else {\n // Otherwise it is not time to yield yet, so step the coroutine synchronously.\n inlineScheduler(coroutine, onStep, onError);\n }\n };\n}\n// Runs the specified coroutine with the specified scheduler. The success or error callback will be invoked when the coroutine finishes.\n/**\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function runCoroutine(coroutine, scheduler, onSuccess, onError, abortSignal) {\n const resume = () => {\n let reschedule;\n const onStep = (stepResult) => {\n if (stepResult.done) {\n // If the coroutine is done, report success.\n onSuccess(stepResult.value);\n }\n else {\n // If the coroutine is not done, resume the coroutine (via the scheduler).\n if (reschedule === undefined) {\n // If reschedule is undefined at this point, then the coroutine must have stepped synchronously, so just flag another loop iteration.\n reschedule = true;\n }\n else {\n // If reschedule is defined at this point, then the coroutine must have stepped asynchronously, so call resume to restart the step loop.\n resume();\n }\n }\n };\n do {\n reschedule = undefined;\n if (!abortSignal || !abortSignal.aborted) {\n scheduler(coroutine, onStep, onError);\n }\n else {\n onError(new Error(\"Aborted\"));\n }\n if (reschedule === undefined) {\n // If reschedule is undefined at this point, then the coroutine must have stepped asynchronously, so stop looping and let the coroutine be resumed later.\n reschedule = false;\n }\n } while (reschedule);\n };\n resume();\n}\n// Runs the specified coroutine synchronously.\n/**\n * @internal\n */\nexport function runCoroutineSync(coroutine, abortSignal) {\n // Run the coroutine with the inline scheduler, storing the returned value, or re-throwing the error (since the error callback will be called synchronously by the inline scheduler).\n let result;\n runCoroutine(coroutine, inlineScheduler, (r) => (result = r), (e) => {\n throw e;\n }, abortSignal);\n // Synchronously return the result of the coroutine.\n return result;\n}\n// Runs the specified coroutine asynchronously with the specified scheduler.\n/**\n * @internal\n */\nexport function runCoroutineAsync(coroutine, scheduler, abortSignal) {\n // Run the coroutine with a yielding scheduler, resolving or rejecting the result promise when the coroutine finishes.\n return new Promise((resolve, reject) => {\n runCoroutine(coroutine, scheduler, resolve, reject, abortSignal);\n });\n}\n/**\n * Given a function that returns a Coroutine<T>, produce a function with the same parameters that returns a T.\n * The returned function runs the coroutine synchronously.\n * @param coroutineFactory A function that returns a Coroutine<T>.\n * @param abortSignal\n * @returns A function that runs the coroutine synchronously.\n * @internal\n */\nexport function makeSyncFunction(coroutineFactory, abortSignal) {\n return (...params) => {\n // Run the coroutine synchronously.\n return runCoroutineSync(coroutineFactory(...params), abortSignal);\n };\n}\n/**\n * Given a function that returns a Coroutine<T>, product a function with the same parameters that returns a Promise<T>.\n * The returned function runs the coroutine asynchronously, yield control of the execution context occasionally to enable a more responsive experience.\n * @param coroutineFactory A function that returns a Coroutine<T>.\n * @param scheduler\n * @param abortSignal\n * @returns A function that runs the coroutine asynchronously.\n * @internal\n */\nexport function makeAsyncFunction(coroutineFactory, scheduler, abortSignal) {\n return (...params) => {\n // Run the coroutine asynchronously.\n return runCoroutineAsync(coroutineFactory(...params), scheduler, abortSignal);\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAACC,SAAS,EAAEC,MAAM,EAAEC,OAAO,EAAE;EACxD,IAAI;IACA,MAAMC,IAAI,GAAGH,SAAS,CAACI,IAAI,CAAC,CAAC;IAC7B,IAAID,IAAI,CAACE,IAAI,EAAE;MACXJ,MAAM,CAACE,IAAI,CAAC;IAChB,CAAC,MACI,IAAI,CAACA,IAAI,CAACG,KAAK,EAAE;MAClB;MACAL,MAAM,CAACE,IAAI,CAAC;IAChB,CAAC,MACI;MACDA,IAAI,CAACG,KAAK,CAACC,IAAI,CAAC,MAAM;QAClBJ,IAAI,CAACG,KAAK,GAAGE,SAAS;QACtBP,MAAM,CAACE,IAAI,CAAC;MAChB,CAAC,EAAED,OAAO,CAAC;IACf;EACJ,CAAC,CACD,OAAOO,KAAK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SAAS,EAAEE,WAAW,CAAC;EACjF,CAAC;AACL","ignoreList":[]},"metadata":{},"sourceType":"module","externalDependencies":[]}
|