Skip to content

Commit

Permalink
fix(runtime/web_worker): Use biased select when getting module result (
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed May 10, 2022
1 parent 2f7f415 commit cb884de
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ jobs:
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
key: 11-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
key: 12-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}

# In main branch, always creates fresh cache
- name: Cache build output (main)
Expand All @@ -252,7 +252,7 @@ jobs:
!./target/*/*.zip
!./target/*/*.tar.gz
key: |
11-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
12-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
# Restore cache from the latest 'main' branch build.
- name: Cache build output (PR)
Expand All @@ -268,7 +268,7 @@ jobs:
!./target/*/*.tar.gz
key: never_saved
restore-keys: |
11-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
12-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
# Don't save cache after building PRs or branches other than 'main'.
- name: Skip save cache (PR)
Expand Down
8 changes: 8 additions & 0 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,14 @@ itest!(event_listener_error_immediate_exit {
exit_code: 1,
});

// https://github.com/denoland/deno/pull/14159#issuecomment-1092285446
itest!(event_listener_error_immediate_exit_worker {
args:
"run --quiet --unstable -A event_listener_error_immediate_exit_worker.ts",
output: "event_listener_error_immediate_exit_worker.ts.out",
exit_code: 1,
});

itest!(set_timeout_error {
args: "run --quiet set_timeout_error.ts",
output: "set_timeout_error.ts.out",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new Worker(
new URL("event_listener_error_immediate_exit.ts", import.meta.url).href,
{ type: "module", deno: { namespace: true } },
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1
error: Uncaught (in worker "") Error: bar
throw new Error("bar");
^
at [WILDCARD]/event_listener_error_immediate_exit.ts:4:9
at [WILDCARD]/event_listener_error_immediate_exit.ts:11:1
error: Uncaught (in promise) Error: Unhandled error in child worker.
at [WILDCARD]
4 changes: 4 additions & 0 deletions runtime/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ impl WebWorker {
let id = self.preload_module(module_specifier, false).await?;
let mut receiver = self.js_runtime.mod_evaluate(id);
tokio::select! {
biased;

maybe_result = &mut receiver => {
debug!("received module evaluate {:#?}", maybe_result);
maybe_result.expect("Module evaluation result not provided.")
Expand All @@ -579,6 +581,8 @@ impl WebWorker {
) -> Result<(), AnyError> {
let mut receiver = self.js_runtime.mod_evaluate(id);
tokio::select! {
biased;

maybe_result = &mut receiver => {
debug!("received worker module evaluate {:#?}", maybe_result);
// If `None` is returned it means that runtime was destroyed before
Expand Down
1 change: 1 addition & 0 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl MainWorker {
) -> T {
loop {
tokio::select! {
biased;
result = &mut fut => {
return result;
}
Expand Down

0 comments on commit cb884de

Please sign in to comment.