@@ -6,6 +6,7 @@ use std::path::PathBuf;
66use std:: process:: ExitCode ;
77use std:: str:: FromStr ;
88use std:: sync:: Arc ;
9+ use std:: time:: Duration ;
910
1011use anyhow:: bail;
1112use anyhow:: Context ;
@@ -34,6 +35,7 @@ use flags::EszipV2ChecksumKind;
3435use flags:: OtelConsoleConfig ;
3536use flags:: OtelKind ;
3637use log:: warn;
38+ use tokio:: time:: timeout;
3739
3840mod env;
3941mod flags;
@@ -319,6 +321,10 @@ fn main() -> Result<ExitCode, anyhow::Error> {
319321 } else {
320322 vec ! [ ]
321323 } ;
324+ let timeout_dur = sub_matches
325+ . get_one :: < u64 > ( "timeout" )
326+ . cloned ( )
327+ . map ( Duration :: from_secs) ;
322328
323329 if import_map_path. is_some ( ) {
324330 warn ! ( concat!(
@@ -382,14 +388,24 @@ fn main() -> Result<ExitCode, anyhow::Error> {
382388 emitter_factory. set_deno_options ( builder. build ( ) ?) ;
383389
384390 let mut metadata = Metadata :: default ( ) ;
385- let eszip = generate_binary_eszip (
391+ let eszip_fut = generate_binary_eszip (
386392 & mut metadata,
387393 Arc :: new ( emitter_factory) ,
388394 None ,
389395 maybe_checksum_kind,
390396 Some ( static_patterns) ,
391- )
392- . await ?;
397+ ) ;
398+
399+ let eszip = if let Some ( dur) = timeout_dur {
400+ match timeout ( dur, eszip_fut) . await {
401+ Ok ( eszip) => eszip,
402+ Err ( _) => {
403+ bail ! ( "Failed to complete the bundle within the given time." )
404+ }
405+ }
406+ } else {
407+ eszip_fut. await
408+ } ?;
393409
394410 let bin = eszip. into_bytes ( ) ;
395411
0 commit comments