Skip to content

Commit 91b4167

Browse files
jasnellMylesBorins
authored andcommitted
http2: remove some unnecessary next ticks
Backport-PR-URL: #20456 PR-URL: #19451 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 1f420fc commit 91b4167

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/internal/http2/core.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ function onSettings() {
364364
session[kUpdateTimer]();
365365
debug(`Http2Session ${sessionName(session[kType])}: new settings received`);
366366
session[kRemoteSettings] = undefined;
367-
process.nextTick(emit, session, 'remoteSettings', session.remoteSettings);
367+
session.emit('remoteSettings', session.remoteSettings);
368368
}
369369

370370
// If the stream exists, an attempt will be made to emit an event
@@ -380,7 +380,7 @@ function onPriority(id, parent, weight, exclusive) {
380380
const emitter = session[kState].streams.get(id) || session;
381381
if (!emitter.destroyed) {
382382
emitter[kUpdateTimer]();
383-
process.nextTick(emit, emitter, 'priority', id, parent, weight, exclusive);
383+
emitter.emit('priority', id, parent, weight, exclusive);
384384
}
385385
}
386386

@@ -394,7 +394,7 @@ function onFrameError(id, type, code) {
394394
`type ${type} on stream ${id}, code: ${code}`);
395395
const emitter = session[kState].streams.get(id) || session;
396396
emitter[kUpdateTimer]();
397-
process.nextTick(emit, emitter, 'frameError', type, code, id);
397+
emitter.emit('frameError', type, code, id);
398398
}
399399

400400
function onAltSvc(stream, origin, alt) {
@@ -404,7 +404,7 @@ function onAltSvc(stream, origin, alt) {
404404
debug(`Http2Session ${sessionName(session[kType])}: altsvc received: ` +
405405
`stream: ${stream}, origin: ${origin}, alt: ${alt}`);
406406
session[kUpdateTimer]();
407-
process.nextTick(emit, session, 'altsvc', alt, origin, stream);
407+
session.emit('altsvc', alt, origin, stream);
408408
}
409409

410410
// Receiving a GOAWAY frame from the connected peer is a signal that no
@@ -734,7 +734,7 @@ function setupHandle(socket, type, options) {
734734
// core will check for session.destroyed before progressing, this
735735
// ensures that those at l`east get cleared out.
736736
if (this.destroyed) {
737-
process.nextTick(emit, this, 'connect', this, socket);
737+
this.emit('connect', this, socket);
738738
return;
739739
}
740740
debug(`Http2Session ${sessionName(type)}: setting up session handle`);
@@ -776,7 +776,7 @@ function setupHandle(socket, type, options) {
776776
options.settings : {};
777777

778778
this.settings(settings);
779-
process.nextTick(emit, this, 'connect', this, socket);
779+
this.emit('connect', this, socket);
780780
}
781781

782782
// Emits a close event followed by an error event if err is truthy. Used
@@ -1227,7 +1227,7 @@ class Http2Session extends EventEmitter {
12271227
}
12281228
}
12291229

1230-
process.nextTick(emit, this, 'timeout');
1230+
this.emit('timeout');
12311231
}
12321232

12331233
ref() {
@@ -1455,8 +1455,8 @@ function streamOnPause() {
14551455
function abort(stream) {
14561456
if (!stream.aborted &&
14571457
!(stream._writableState.ended || stream._writableState.ending)) {
1458-
process.nextTick(emit, stream, 'aborted');
14591458
stream[kState].flags |= STREAM_FLAGS_ABORTED;
1459+
stream.emit('aborted');
14601460
}
14611461
}
14621462

@@ -1578,7 +1578,7 @@ class Http2Stream extends Duplex {
15781578
}
15791579
}
15801580

1581-
process.nextTick(emit, this, 'timeout');
1581+
this.emit('timeout');
15821582
}
15831583

15841584
// true if the HEADERS frame has been sent

0 commit comments

Comments
 (0)