Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.5 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | const events_1 = require("events");
|
---|
3 | const async_hooks_1 = require("async_hooks");
|
---|
4 | const kEventEmitter = Symbol('kEventEmitter');
|
---|
5 | const kAsyncResource = Symbol('kAsyncResource');
|
---|
6 | class EventEmitterReferencingAsyncResource extends async_hooks_1.AsyncResource {
|
---|
7 | constructor(ee, type, options) {
|
---|
8 | super(type, options);
|
---|
9 | this[kEventEmitter] = ee;
|
---|
10 | }
|
---|
11 | get eventEmitter() {
|
---|
12 | return this[kEventEmitter];
|
---|
13 | }
|
---|
14 | }
|
---|
15 | class EventEmitterAsyncResource extends events_1.EventEmitter {
|
---|
16 | constructor(options) {
|
---|
17 | let name;
|
---|
18 | if (typeof options === 'string') {
|
---|
19 | name = options;
|
---|
20 | options = undefined;
|
---|
21 | }
|
---|
22 | else {
|
---|
23 | name = (options === null || options === void 0 ? void 0 : options.name) || new.target.name;
|
---|
24 | }
|
---|
25 | super(options);
|
---|
26 | this[kAsyncResource] =
|
---|
27 | new EventEmitterReferencingAsyncResource(this, name, options);
|
---|
28 | }
|
---|
29 | emit(event, ...args) {
|
---|
30 | return this.asyncResource.runInAsyncScope(super.emit, this, event, ...args);
|
---|
31 | }
|
---|
32 | emitDestroy() {
|
---|
33 | this.asyncResource.emitDestroy();
|
---|
34 | }
|
---|
35 | asyncId() {
|
---|
36 | return this.asyncResource.asyncId();
|
---|
37 | }
|
---|
38 | triggerAsyncId() {
|
---|
39 | return this.asyncResource.triggerAsyncId();
|
---|
40 | }
|
---|
41 | get asyncResource() {
|
---|
42 | return this[kAsyncResource];
|
---|
43 | }
|
---|
44 | static get EventEmitterAsyncResource() { return EventEmitterAsyncResource; }
|
---|
45 | }
|
---|
46 | module.exports = EventEmitterAsyncResource;
|
---|
47 | //# sourceMappingURL=index.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.