-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Description
What is the problem this feature will solve?
Does it make sense to add a method to AsyncLocalStorage that returns Disposable?
What is the feature you are proposing to solve the problem?
This is the example from AsyncLocalStorage using .run
, which introduces a callback and a level of nesting that comes with that.
http.createServer((req, res) => {
asyncLocalStorage.run(idSeq++, () => {
logWithId('start');
// Imagine any chain of async operations here
setImmediate(() => {
logWithId('finish');
res.end();
});
});
})
With with explicit resource management this could be:
http.createServer((req, res) => {
using _id = asyncLocalStorage._PROPOSED(idSeq++)
logWithId('start');
// Imagine any chain of async operations here
setImmediate(() => {
logWithId('finish');
res.end();
});
})
enterWith
currently returns undefined
, could that be updated to return a Disposable?
What alternatives have you considered?
This could be built in user-land, I think
function enterWith<T>(als: AsyncLocalStorage<T>, store: T) {
const oldStore = als.getStore()
console.debug(als.enterWith(store))
const dispose = new DisposableStack()
dispose.defer(() => als.enterWith(oldStore))
return dispose
}
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Type
Projects
Status
Awaiting Triage