Skip to content

Commit e4c10e1

Browse files
jasnellMylesBorins
authored andcommitted
http2: remove some unnecessary next ticks
Backport-PR-URL: #20456 PR-URL: #19451 Reviewed-By: Matteo Collina <[email protected]>
1 parent da185ce commit e4c10e1

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
@@ -361,7 +361,7 @@ function onSettings() {
361361
session[kUpdateTimer]();
362362
debug(`Http2Session ${sessionName(session[kType])}: new settings received`);
363363
session[kRemoteSettings] = undefined;
364-
process.nextTick(emit, session, 'remoteSettings', session.remoteSettings);
364+
session.emit('remoteSettings', session.remoteSettings);
365365
}
366366

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

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

397397
function onAltSvc(stream, origin, alt) {
@@ -401,7 +401,7 @@ function onAltSvc(stream, origin, alt) {
401401
debug(`Http2Session ${sessionName(session[kType])}: altsvc received: ` +
402402
`stream: ${stream}, origin: ${origin}, alt: ${alt}`);
403403
session[kUpdateTimer]();
404-
process.nextTick(emit, session, 'altsvc', alt, origin, stream);
404+
session.emit('altsvc', alt, origin, stream);
405405
}
406406

407407
// Receiving a GOAWAY frame from the connected peer is a signal that no
@@ -731,7 +731,7 @@ function setupHandle(socket, type, options) {
731731
// core will check for session.destroyed before progressing, this
732732
// ensures that those at l`east get cleared out.
733733
if (this.destroyed) {
734-
process.nextTick(emit, this, 'connect', this, socket);
734+
this.emit('connect', this, socket);
735735
return;
736736
}
737737
debug(`Http2Session ${sessionName(type)}: setting up session handle`);
@@ -773,7 +773,7 @@ function setupHandle(socket, type, options) {
773773
options.settings : {};
774774

775775
this.settings(settings);
776-
process.nextTick(emit, this, 'connect', this, socket);
776+
this.emit('connect', this, socket);
777777
}
778778

779779
// Emits a close event followed by an error event if err is truthy. Used
@@ -1224,7 +1224,7 @@ class Http2Session extends EventEmitter {
12241224
}
12251225
}
12261226

1227-
process.nextTick(emit, this, 'timeout');
1227+
this.emit('timeout');
12281228
}
12291229

12301230
ref() {
@@ -1452,8 +1452,8 @@ function streamOnPause() {
14521452
function abort(stream) {
14531453
if (!stream.aborted &&
14541454
!(stream._writableState.ended || stream._writableState.ending)) {
1455-
process.nextTick(emit, stream, 'aborted');
14561455
stream[kState].flags |= STREAM_FLAGS_ABORTED;
1456+
stream.emit('aborted');
14571457
}
14581458
}
14591459

@@ -1575,7 +1575,7 @@ class Http2Stream extends Duplex {
15751575
}
15761576
}
15771577

1578-
process.nextTick(emit, this, 'timeout');
1578+
this.emit('timeout');
15791579
}
15801580

15811581
// true if the HEADERS frame has been sent

0 commit comments

Comments
 (0)