Skip to content

Commit 74aba42

Browse files
committed
Fix web_features example and issue with error propagation
1 parent 76d7161 commit 74aba42

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ required-features = ["worker"]
253253
name = "default_threaded_worker"
254254
required-features = ["worker"]
255255

256+
[[example]]
257+
name = "web_features"
258+
required-features = ["web"]
259+
256260
[[example]]
257261
name = "worker_pool"
258262
required-features = ["worker"]

src/inner_runtime.rs

+44-23
Original file line numberDiff line numberDiff line change
@@ -645,33 +645,33 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
645645
{
646646
// Manually implement tokio::select
647647
std::future::poll_fn(|cx| {
648-
if let Poll::Ready(t) = fut.poll_unpin(cx) {
649-
return if let Poll::Ready(Err(e)) =
650-
self.deno_runtime().poll_event_loop(cx, poll_options)
651-
{
652-
// Run one more tick to check for errors
648+
let evt_status = self.deno_runtime().poll_event_loop(cx, poll_options);
649+
let fut_status = fut.poll_unpin(cx);
650+
651+
match (evt_status, fut_status) {
652+
(Poll::Ready(Err(e)), _) => {
653+
// Event loop failed
653654
Poll::Ready(Err(e.into()))
654-
} else {
655-
// No errors - continue
656-
Poll::Ready(t.map_err(Into::into))
657-
};
658-
}
655+
}
659656

660-
if let Poll::Ready(Err(e)) = self.deno_runtime().poll_event_loop(cx, poll_options) {
661-
// Event loop failed
662-
return Poll::Ready(Err(e.into()));
663-
}
657+
(_, Poll::Pending) => {
658+
// Continue polling
659+
Poll::Pending
660+
}
664661

665-
if self
666-
.deno_runtime()
667-
.poll_event_loop(cx, poll_options)
668-
.is_ready()
669-
{
670-
// Event loop resolved - continue
671-
println!("Event loop resolved");
672-
}
662+
(_, Poll::Ready(t)) => {
663+
for _ in 0..100 {
664+
if let Poll::Ready(Err(e)) =
665+
self.deno_runtime().poll_event_loop(cx, poll_options)
666+
{
667+
return Poll::Ready(Err(e.into()));
668+
}
669+
}
673670

674-
Poll::Pending
671+
// Future resolved
672+
Poll::Ready(t.map_err(Into::into))
673+
}
674+
}
675675
})
676676
.await
677677
}
@@ -1257,6 +1257,27 @@ mod test_inner_runtime {
12571257
});
12581258
}
12591259

1260+
#[test]
1261+
fn test_deep_error() {
1262+
let module = Module::new(
1263+
"test.js",
1264+
"
1265+
await new Promise(r => setTimeout(r)); throw 'huh';
1266+
",
1267+
);
1268+
1269+
let mut runtime =
1270+
InnerRuntime::<JsRuntime>::new(RuntimeOptions::default(), CancellationToken::new())
1271+
.expect("Could not load runtime");
1272+
1273+
let rt = &mut runtime;
1274+
run_async_task(|| async move {
1275+
let result = rt.load_modules(Some(&module), vec![]).await;
1276+
assert!(result.is_err());
1277+
Ok(())
1278+
});
1279+
}
1280+
12601281
#[test]
12611282
fn test_serialize_deep_fn() {
12621283
let module = Module::new(

0 commit comments

Comments
 (0)