Skip to content

workers: make Worker async disposable #58385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented May 19, 2025

await using worker = new Worker(...);

```js
await using worker = new Worker(...);
```
@jasnell jasnell added semver-minor PRs that contain new features and should be released in the next minor version. worker Issues and PRs related to Worker support. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v23.x PRs that should not land on the v23.x-staging branch and should not be released in v23.x. labels May 19, 2025
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label May 19, 2025
@jasnell jasnell requested review from mcollina, addaleax and anonrig May 19, 2025 02:37
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented May 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.24%. Comparing base (20c4b80) to head (658a86f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58385      +/-   ##
==========================================
+ Coverage   90.23%   90.24%   +0.01%     
==========================================
  Files         633      633              
  Lines      186883   186888       +5     
  Branches    36695    36688       -7     
==========================================
+ Hits       168632   168656      +24     
+ Misses      11040    11039       -1     
+ Partials     7211     7193      -18     
Files with missing lines Coverage Δ
lib/internal/worker.js 99.82% <100.00%> (+<0.01%) ⬆️

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with or without the nit; and s/^workers/worker/ in the commit message.

Noting that the code change can be safely backported to release lines that have Symbol.asyncDispose but not the ERM itself; and splitting this into two commits (one that adds [SymbolAsyncDispose](), tests it by calling explicitly, and documents without code example; and another for v24+ adding using in tests in docs) might make it more straightforward for releasers.

Comment on lines +4 to +10
let w;
{
// Verifies that the worker is async disposable
await using worker = new Worker('for(;;) {}', { eval: true });
w = worker;
w.on('exit', common.mustCall());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: was w meant to be checked after the scope? If not, we don't really need it.

Suggested change
let w;
{
// Verifies that the worker is async disposable
await using worker = new Worker('for(;;) {}', { eval: true });
w = worker;
w.on('exit', common.mustCall());
}
{
// Verifies that the worker is async disposable
await using worker = new Worker('for(;;) {}', { eval: true });
worker.on('exit', common.mustCall());
}

@aduh95
Copy link
Contributor

aduh95 commented May 19, 2025

Why dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. ? That feels like something we'd want to backport. Could you follow the same approach of #58206, i.e. avoid using the new syntax so this can be backported, and add a TODO to have a follow-up to test with the await using syntax?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. dont-land-on-v23.x PRs that should not land on the v23.x-staging branch and should not be released in v23.x. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants