Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] [wasm] propagate aborted startup to top most promise #78764

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/mono/wasm/runtime/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { preAllocatePThreadWorkerPool, instantiateWasmPThreadWorkerPool } from "
let config: MonoConfigInternal = undefined as any;
let configLoaded = false;
let isCustomStartup = false;
export const dotnetReady = createPromiseController<any>();
export const afterConfigLoaded = createPromiseController<void>();
export const afterInstantiateWasm = createPromiseController<void>();
export const beforePreInit = createPromiseController<void>();
Expand Down Expand Up @@ -69,13 +70,17 @@ export function configure_emscripten_startup(module: DotnetModule, exportedAPI:
// execution order == [5] ==
module.postRun = [() => postRunAsync(userpostRun)];
// execution order == [6] ==
module.ready = module.ready.then(async () => {

module.ready.then(async () => {
// wait for previous stage
await afterPostRun.promise;
// - here we resolve the promise returned by createDotnetRuntime export
return exportedAPI;
// - any code after createDotnetRuntime is executed now
dotnetReady.promise_control.resolve(exportedAPI);
}).catch(err => {
dotnetReady.promise_control.reject(err);
});
module.ready = dotnetReady.promise;
// execution order == [*] ==
if (!module.onAbort) {
module.onAbort = () => mono_on_abort;
Expand Down Expand Up @@ -220,6 +225,7 @@ async function postRunAsync(userpostRun: (() => void)[]) {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function abort_startup(reason: any, should_exit: boolean): void {
if (runtimeHelpers.diagnosticTracing) console.trace("MONO_WASM: abort_startup");
dotnetReady.promise_control.reject(reason);
afterInstantiateWasm.promise_control.reject(reason);
beforePreInit.promise_control.reject(reason);
afterPreInit.promise_control.reject(reason);
Expand Down