@@ -2274,6 +2274,110 @@ addToLibrary({
22742274 $noExitRuntime__postset: ( ) => addAtModule ( makeModuleReceive ( 'noExitRuntime' ) ) ,
22752275 $noExitRuntime : { { { ! EXIT_RUNTIME } } } ,
22762276
2277+ // A counter of dependencies for calling run(). If we need to
2278+ // do asynchronous work before running, increment this and
2279+ // decrement it. Incrementing must happen in a place like
2280+ // Module.preRun (used by emcc to add file preloading).
2281+ // Note that you can add dependencies in preRun, even though
2282+ // it happens right before run - run will be postponed until
2283+ // the dependencies are met.
2284+ $runDependencies__internal : true ,
2285+ $runDependencies : 0 ,
2286+ // overridden to take different actions when all run dependencies are fulfilled
2287+ $dependenciesFulfilled__internal : true ,
2288+ $dependenciesFulfilled : null ,
2289+ #if ASSERTIONS
2290+ $runDependencyTracking__internal: true ,
2291+ $runDependencyTracking : { } ,
2292+ $runDependencyWatcher__internal : true ,
2293+ $runDependencyWatcher : null ,
2294+ #endif
2295+
2296+ $addRunDependency__deps : [ '$runDependencies' ,
2297+ #if ASSERTIONS
2298+ '$runDependencyTracking' ,
2299+ '$runDependencyWatcher' ,
2300+ #endif
2301+ ] ,
2302+ $addRunDependency : ( id ) = > {
2303+ runDependencies ++ ;
2304+
2305+ #if expectToReceiveOnModule ( 'monitorRunDependencies' )
2306+ Module [ 'monitorRunDependencies' ] ?. ( runDependencies ) ;
2307+ #endif
2308+
2309+ #if ASSERTIONS
2310+ #if RUNTIME_DEBUG
2311+ dbg ( 'addRunDependency' , id ) ;
2312+ #endif
2313+ assert ( id , 'addRunDependency requires an ID' )
2314+ assert ( ! runDependencyTracking [ id ] ) ;
2315+ runDependencyTracking [ id ] = 1 ;
2316+ if ( runDependencyWatcher === null && typeof setInterval != 'undefined' ) {
2317+ // Check for missing dependencies every few seconds
2318+ runDependencyWatcher = setInterval ( ( ) => {
2319+ if ( ABORT ) {
2320+ clearInterval ( runDependencyWatcher ) ;
2321+ runDependencyWatcher = null ;
2322+ return ;
2323+ }
2324+ var shown = false ;
2325+ for ( var dep in runDependencyTracking ) {
2326+ if ( ! shown ) {
2327+ shown = true ;
2328+ err ( 'still waiting on run dependencies:' ) ;
2329+ }
2330+ err ( `dependency: ${ dep } ` ) ;
2331+ }
2332+ if ( shown ) {
2333+ err ( '(end of list)' ) ;
2334+ }
2335+ } , 10000 ) ;
2336+ #if ENVIRONMENT_MAY_BE_NODE
2337+ // Prevent this timer from keeping the runtime alive if nothing
2338+ // else is.
2339+ runDependencyWatcher . unref ?. ( )
2340+ #endif
2341+ }
2342+ #endif
2343+ } ,
2344+
2345+ $removeRunDependency__deps: [ '$runDependencies' , '$dependenciesFulfilled' ,
2346+ #if ASSERTIONS
2347+ '$runDependencyTracking' ,
2348+ '$runDependencyWatcher' ,
2349+ #endif
2350+ ] ,
2351+ $removeRunDependency : ( id ) = > {
2352+ runDependencies -- ;
2353+
2354+ #if expectToReceiveOnModule ( 'monitorRunDependencies' )
2355+ Module [ 'monitorRunDependencies' ] ?. ( runDependencies ) ;
2356+ #endif
2357+
2358+ #if ASSERTIONS
2359+ #if RUNTIME_DEBUG
2360+ dbg ( 'removeRunDependency' , id ) ;
2361+ #endif
2362+ assert ( id , 'removeRunDependency requires an ID' ) ;
2363+ assert ( runDependencyTracking [ id ] ) ;
2364+ delete runDependencyTracking [ id ] ;
2365+ #endif
2366+ if ( runDependencies == 0 ) {
2367+ #if ASSERTIONS
2368+ if ( runDependencyWatcher !== null ) {
2369+ clearInterval ( runDependencyWatcher ) ;
2370+ runDependencyWatcher = null ;
2371+ }
2372+ #endif
2373+ if ( dependenciesFulfilled ) {
2374+ var callback = dependenciesFulfilled ;
2375+ dependenciesFulfilled = null ;
2376+ callback ( ) ; // can add another dependenciesFulfilled
2377+ }
2378+ }
2379+ } ,
2380+
22772381 // The following addOn<X> functions are for adding runtime callbacks at
22782382 // various executions points. Each addOn<X> function has a corresponding
22792383 // compiled time version named addAt<X> that will instead inline during
0 commit comments