-
-
Notifications
You must be signed in to change notification settings - Fork 32k
util: add util.disposer helper to wrap a dispose function #58585
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
base: main
Are you sure you want to change the base?
Conversation
f62eec4
to
4c43e17
Compare
Is this not the same functionality that |
Add `util.disposer` and `util.asyncDisposer` to conveniently wrap a function to be a disposable, and allow it to be used with `using` declaration.
It is. This is a helper function if you just want to wrap a function, without the need to create a |
4c43e17
to
c1f1080
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #58585 +/- ##
==========================================
- Coverage 90.24% 90.20% -0.05%
==========================================
Files 635 636 +1
Lines 187633 187580 -53
Branches 36853 36852 -1
==========================================
- Hits 169336 169213 -123
- Misses 11082 11153 +71
+ Partials 7215 7214 -1
🚀 New features to boost your workflow:
|
|
||
```mjs | ||
{ | ||
await using _ = util.disposer(async function disposer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await using _ = util.disposer(async function disposer() { | |
await using _ = util.asyncDisposer(async function disposer() { |
defineLazyProperties( | ||
module.exports, | ||
'internal/util/disposer', | ||
['disposer', 'asyncDisposer', 'Disposer', 'AsyncDisposer'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disposer
and AsyncDisposer
are not actually exported?
with `using` declaration. | ||
|
||
If an error is thrown in the function, instead of returning a promise, | ||
the error will be wrapped in a rejected promise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that DisposableStack.defer(...)
exists I'm not super convinced that this is needed or all that useful.
{
using ds = new DisposableStack();
ds.defer(onDispose);
}
Add
util.disposer
andutil.asyncDisposer
to conveniently wrap afunction to be a disposable, and allow it to be used with
using
declaration.