@@ -79,6 +79,8 @@ use deno_facade::EmitterFactory;
7979use deno_facade:: EszipPayloadKind ;
8080use deno_facade:: Metadata ;
8181use either:: Either ;
82+ use either:: Either :: Left ;
83+ use either:: Either :: Right ;
8284use ext_event_worker:: events:: WorkerEventWithMetadata ;
8385use ext_runtime:: cert:: ValueRootCertStoreProvider ;
8486use ext_runtime:: external_memory:: CustomAllocator ;
@@ -1328,47 +1330,6 @@ where
13281330 return ( Err ( err) , 0i64 ) ;
13291331 }
13301332
1331- if inspector. is_some ( ) {
1332- let ret = spawn_blocking_non_send ( || {
1333- let state = self . runtime_state . clone ( ) ;
1334- let _guard = scopeguard:: guard_on_unwind ( ( ) , |_| {
1335- state. terminated . raise ( ) ;
1336- } ) ;
1337-
1338- self . assert_isolate_not_locked ( ) ;
1339- let mut locker = self . with_locker ( ) ;
1340-
1341- {
1342- let _guard =
1343- scopeguard:: guard ( state. found_inspector_session . clone ( ) , |v| {
1344- v. raise ( ) ;
1345- } ) ;
1346-
1347- // XXX(Nyannyacha): Suppose the user skips this function by passing
1348- // the `--inspect` argument. In that case, the runtime may terminate
1349- // before the inspector session is connected if the function doesn't
1350- // have a long execution time. Should we wait for an inspector session
1351- // to connect with the V8?
1352- locker. wait_for_inspector_session ( ) ;
1353- }
1354-
1355- if locker. termination_request_token . is_cancelled ( ) {
1356- state. terminated . raise ( ) ;
1357- return false ;
1358- }
1359-
1360- true
1361- } )
1362- . await
1363- . map_err ( Error :: from) ;
1364-
1365- match ret {
1366- Ok ( true ) => { }
1367- Ok ( false ) => return ( Ok ( ( ) ) , 0i64 ) ,
1368- Err ( err) => return ( Err ( err) , 0i64 ) ,
1369- }
1370- }
1371-
13721333 let Some ( main_module_id) = self . main_module_id else {
13731334 return ( Err ( anyhow ! ( "failed to get main module id" ) ) , 0 ) ;
13741335 } ;
@@ -1388,15 +1349,42 @@ where
13881349 async {
13891350 self . assert_isolate_not_locked ( ) ;
13901351 let mut locker = self . with_locker ( ) ;
1391-
13921352 let op_state = locker. js_runtime . op_state ( ) ;
1353+ let state = locker. runtime_state . clone ( ) ;
1354+
1355+ if inspector. is_some ( ) {
1356+ let _guard = scopeguard:: guard_on_unwind ( ( ) , |_| {
1357+ state. terminated . raise ( ) ;
1358+ } ) ;
1359+
1360+ {
1361+ let _guard = scopeguard:: guard (
1362+ state. found_inspector_session . clone ( ) ,
1363+ |v| {
1364+ v. raise ( ) ;
1365+ } ,
1366+ ) ;
1367+
1368+ // XXX(Nyannyacha): Suppose the user skips this function by
1369+ // passing the `--inspect` argument. In that case, the runtime
1370+ // may terminate before the inspector session is connected if
1371+ // the function doesn't have a long execution time. Should we
1372+ // wait for an inspector session to connect with the V8?
1373+ locker. wait_for_inspector_session ( ) ;
1374+ }
1375+
1376+ if locker. termination_request_token . is_cancelled ( ) {
1377+ state. terminated . raise ( ) ;
1378+ return Left ( ( ) ) ;
1379+ }
1380+ }
13931381
1394- with_cpu_metrics_guard (
1382+ Right ( with_cpu_metrics_guard (
13951383 op_state,
13961384 & maybe_cpu_usage_metrics_tx,
13971385 & mut accumulated_cpu_time_ns,
13981386 || locker. js_runtime . mod_evaluate ( main_module_id) ,
1399- )
1387+ ) )
14001388 }
14011389 . instrument ( span) ,
14021390 )
@@ -1405,7 +1393,10 @@ where
14051393 } ;
14061394
14071395 let mut mod_ret_rx = match mod_fut_ret {
1408- Ok ( v) => v,
1396+ Ok ( v) => match v {
1397+ Left ( _give_up) => return ( Ok ( ( ) ) , 0i64 ) ,
1398+ Right ( fut) => fut,
1399+ } ,
14091400 Err ( err) => {
14101401 return (
14111402 Err ( err) . context ( "failed to load the module" ) ,
0 commit comments