Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1013 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | # eventemitter-asyncresource - AsyncResource integration for EventEmitter
|
---|
| 2 |
|
---|
| 3 | Integrates [`EventEmitter`][] with [`AsyncResource`][] for `EventEmitter`s that
|
---|
| 4 | require manual async tracking.
|
---|
| 5 |
|
---|
| 6 | ```js
|
---|
| 7 | const { EventEmitterAsyncResource } = require('eventemitter-asyncresource');
|
---|
| 8 |
|
---|
| 9 | // Async tracking tooling will identify this as 'Q'.
|
---|
| 10 | const ee = new EventEmitterAsyncResource({ name: 'Q' });
|
---|
| 11 |
|
---|
| 12 | // 'foo' listeners will run in this EventEmitter’s async context.P
|
---|
| 13 | ee.emit('foo');
|
---|
| 14 | ```
|
---|
| 15 |
|
---|
| 16 | The `EventEmitterAsyncResource` class has the same methods and takes the same
|
---|
| 17 | options as `EventEmitter` and `AsyncResource` themselves.
|
---|
| 18 |
|
---|
| 19 | It provides an `.asyncResource` property that allows accessing the async
|
---|
| 20 | resource in question, which in turn provides the original `EventEmitter` via
|
---|
| 21 | `.eventEmitter`, i.e. in the above example
|
---|
| 22 | `ee.asyncResource.eventEmitter === ee`.
|
---|
| 23 |
|
---|
| 24 | [`EventEmitter`]: https://nodejs.org/api/events.html#events_class_eventemitter
|
---|
| 25 | [`AsyncResource`]: https://nodejs.org/api/async_hooks.html#async_hooks_class_asyncresource
|
---|
Note:
See
TracBrowser
for help on using the repository browser.