@@ -6,6 +6,7 @@ use std::path::PathBuf;
6
6
use std:: process:: ExitCode ;
7
7
use std:: str:: FromStr ;
8
8
use std:: sync:: Arc ;
9
+ use std:: time:: Duration ;
9
10
10
11
use anyhow:: bail;
11
12
use anyhow:: Context ;
@@ -34,6 +35,7 @@ use flags::EszipV2ChecksumKind;
34
35
use flags:: OtelConsoleConfig ;
35
36
use flags:: OtelKind ;
36
37
use log:: warn;
38
+ use tokio:: time:: timeout;
37
39
38
40
mod env;
39
41
mod flags;
@@ -319,6 +321,10 @@ fn main() -> Result<ExitCode, anyhow::Error> {
319
321
} else {
320
322
vec ! [ ]
321
323
} ;
324
+ let timeout_dur = sub_matches
325
+ . get_one :: < u64 > ( "timeout" )
326
+ . cloned ( )
327
+ . map ( Duration :: from_secs) ;
322
328
323
329
if import_map_path. is_some ( ) {
324
330
warn ! ( concat!(
@@ -382,14 +388,24 @@ fn main() -> Result<ExitCode, anyhow::Error> {
382
388
emitter_factory. set_deno_options ( builder. build ( ) ?) ;
383
389
384
390
let mut metadata = Metadata :: default ( ) ;
385
- let eszip = generate_binary_eszip (
391
+ let eszip_fut = generate_binary_eszip (
386
392
& mut metadata,
387
393
Arc :: new ( emitter_factory) ,
388
394
None ,
389
395
maybe_checksum_kind,
390
396
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
+ } ?;
393
409
394
410
let bin = eszip. into_bytes ( ) ;
395
411
0 commit comments