@@ -33,6 +33,7 @@ import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";
3333let config : MonoConfigInternal = undefined as any ;
3434let configLoaded = false ;
3535let isCustomStartup = false ;
36+ export const dotnetReady = createPromiseController < any > ( ) ;
3637export const afterConfigLoaded = createPromiseController < void > ( ) ;
3738export const afterInstantiateWasm = createPromiseController < void > ( ) ;
3839export const beforePreInit = createPromiseController < void > ( ) ;
@@ -72,15 +73,19 @@ export function configure_emscripten_startup(module: DotnetModule, exportedAPI:
7273 // execution order == [5] ==
7374 module . postRun = [ ( ) => postRunAsync ( userpostRun ) ] ;
7475 // execution order == [6] ==
75- module . ready = module . ready . then ( async ( ) => {
76+
77+ module . ready . then ( async ( ) => {
7678 // wait for previous stage
7779 await afterPostRun . promise ;
7880 // startup end
7981 endMeasure ( mark , MeasuredBlock . emscriptenStartup ) ;
8082 // - here we resolve the promise returned by createDotnetRuntime export
81- return exportedAPI ;
8283 // - any code after createDotnetRuntime is executed now
84+ dotnetReady . promise_control . resolve ( exportedAPI ) ;
85+ } ) . catch ( err => {
86+ dotnetReady . promise_control . reject ( err ) ;
8387 } ) ;
88+ module . ready = dotnetReady . promise ;
8489 // execution order == [*] ==
8590 if ( ! module . onAbort ) {
8691 module . onAbort = ( ) => mono_on_abort ;
@@ -235,6 +240,7 @@ async function postRunAsync(userpostRun: (() => void)[]) {
235240// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
236241export function abort_startup ( reason : any , should_exit : boolean ) : void {
237242 if ( runtimeHelpers . diagnosticTracing ) console . trace ( "MONO_WASM: abort_startup" ) ;
243+ dotnetReady . promise_control . reject ( reason ) ;
238244 afterInstantiateWasm . promise_control . reject ( reason ) ;
239245 beforePreInit . promise_control . reject ( reason ) ;
240246 afterPreInit . promise_control . reject ( reason ) ;
0 commit comments