Skip to content

Commit ab75548

Browse files
committed
http2: remove some unnecessary next ticks
PR-URL: #19451 Reviewed-By: Matteo Collina <[email protected]>
1 parent e714da6 commit ab75548

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/internal/http2/core.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ function onSettings() {
409409
session[kUpdateTimer]();
410410
debug(`Http2Session ${sessionName(session[kType])}: new settings received`);
411411
session[kRemoteSettings] = undefined;
412-
process.nextTick(emit, session, 'remoteSettings', session.remoteSettings);
412+
session.emit('remoteSettings', session.remoteSettings);
413413
}
414414

415415
// If the stream exists, an attempt will be made to emit an event
@@ -425,7 +425,7 @@ function onPriority(id, parent, weight, exclusive) {
425425
const emitter = session[kState].streams.get(id) || session;
426426
if (!emitter.destroyed) {
427427
emitter[kUpdateTimer]();
428-
process.nextTick(emit, emitter, 'priority', id, parent, weight, exclusive);
428+
emitter.emit('priority', id, parent, weight, exclusive);
429429
}
430430
}
431431

@@ -439,7 +439,7 @@ function onFrameError(id, type, code) {
439439
`type ${type} on stream ${id}, code: ${code}`);
440440
const emitter = session[kState].streams.get(id) || session;
441441
emitter[kUpdateTimer]();
442-
process.nextTick(emit, emitter, 'frameError', type, code, id);
442+
emitter.emit('frameError', type, code, id);
443443
}
444444

445445
function onAltSvc(stream, origin, alt) {
@@ -449,7 +449,7 @@ function onAltSvc(stream, origin, alt) {
449449
debug(`Http2Session ${sessionName(session[kType])}: altsvc received: ` +
450450
`stream: ${stream}, origin: ${origin}, alt: ${alt}`);
451451
session[kUpdateTimer]();
452-
process.nextTick(emit, session, 'altsvc', alt, origin, stream);
452+
session.emit('altsvc', alt, origin, stream);
453453
}
454454

455455
// Receiving a GOAWAY frame from the connected peer is a signal that no
@@ -771,7 +771,7 @@ function setupHandle(socket, type, options) {
771771
// core will check for session.destroyed before progressing, this
772772
// ensures that those at l`east get cleared out.
773773
if (this.destroyed) {
774-
process.nextTick(emit, this, 'connect', this, socket);
774+
this.emit('connect', this, socket);
775775
return;
776776
}
777777
debug(`Http2Session ${sessionName(type)}: setting up session handle`);
@@ -813,7 +813,7 @@ function setupHandle(socket, type, options) {
813813
options.settings : {};
814814

815815
this.settings(settings);
816-
process.nextTick(emit, this, 'connect', this, socket);
816+
this.emit('connect', this, socket);
817817
}
818818

819819
// Emits a close event followed by an error event if err is truthy. Used
@@ -1262,7 +1262,7 @@ class Http2Session extends EventEmitter {
12621262
}
12631263
}
12641264

1265-
process.nextTick(emit, this, 'timeout');
1265+
this.emit('timeout');
12661266
}
12671267

12681268
ref() {
@@ -1485,8 +1485,8 @@ function streamOnPause() {
14851485
function abort(stream) {
14861486
if (!stream.aborted &&
14871487
!(stream._writableState.ended || stream._writableState.ending)) {
1488-
process.nextTick(emit, stream, 'aborted');
14891488
stream[kState].flags |= STREAM_FLAGS_ABORTED;
1489+
stream.emit('aborted');
14901490
}
14911491
}
14921492

@@ -1612,7 +1612,7 @@ class Http2Stream extends Duplex {
16121612
}
16131613
}
16141614

1615-
process.nextTick(emit, this, 'timeout');
1615+
this.emit('timeout');
16161616
}
16171617

16181618
// true if the HEADERS frame has been sent

0 commit comments

Comments
 (0)