Open
Description
Events are widely used in async operations, e.g. Host APIs like Node.js EventEmitters Server
, Stream
, and web browser EventTargets XMLHttpRequest
.
Expectations can be that the invocation of addEventListener
acts as a creation of an async resource and capture the current async context frame to be used when the event is emitted.
We could make this an option passed into addEventListener
which would essentially be a convenient path for manually calling AsyncContext.wrap
on the handler function.
eventTarget.addEventListener('foo', () => {}, {
captureAsyncContext: true,
});
Originally posted by @jasnell and @jridgewell.