Skip to content

Commit 4ed7fe5

Browse files
committed
[major] Rename the allowMultipleEventsPerMicrotask option
Rename the `allowMultipleEventsPerMicrotask` option to `allowSynchronousEvents`.
1 parent fccc580 commit 4ed7fe5

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

doc/ws.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ This class represents a WebSocket server. It extends the `EventEmitter`.
7272
### new WebSocketServer(options[, callback])
7373

7474
- `options` {Object}
75-
- `allowMultipleEventsPerMicrotask` {Boolean} Specifies whether or not to
76-
process more than one of the `'message'`, `'ping'`, and `'pong'` events per
77-
microtask. To improve compatibility with the WHATWG standard, the default
78-
value is `false`. Setting it to `true` improves performance slightly.
75+
- `allowSynchronousEvents` {Boolean} Specifies whether any of the `'message'`,
76+
`'ping'`, and `'pong'` events can be emitted multiple times in the same
77+
tick. To improve compatibility with the WHATWG standard, the default value
78+
is `false`. Setting it to `true` improves performance slightly.
7979
- `backlog` {Number} The maximum length of the queue of pending connections.
8080
- `clientTracking` {Boolean} Specifies whether or not to track clients.
8181
- `handleProtocols` {Function} A function which can be used to handle the
@@ -296,10 +296,10 @@ This class represents a WebSocket. It extends the `EventEmitter`.
296296
- `address` {String|url.URL} The URL to which to connect.
297297
- `protocols` {String|Array} The list of subprotocols.
298298
- `options` {Object}
299-
- `allowMultipleEventsPerMicrotask` {Boolean} Specifies whether or not to
300-
process more than one of the `'message'`, `'ping'`, and `'pong'` events per
301-
microtask. To improve compatibility with the WHATWG standard, the default
302-
value is `false`. Setting it to `true` improves performance slightly.
299+
- `allowSynchronousEvents` {Boolean} Specifies whether any of the `'message'`,
300+
`'ping'`, and `'pong'` events can be emitted multiple times in the same
301+
tick. To improve compatibility with the WHATWG standard, the default value
302+
is `false`. Setting it to `true` improves performance slightly.
303303
- `finishRequest` {Function} A function which can be used to customize the
304304
headers of each http request before it is sent. See description below.
305305
- `followRedirects` {Boolean} Whether or not to follow redirects. Defaults to

lib/receiver.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class Receiver extends Writable {
3939
* Creates a Receiver instance.
4040
*
4141
* @param {Object} [options] Options object
42-
* @param {Boolean} [options.allowMultipleEventsPerMicrotask=false] Specifies
43-
* whether or not to process more than one of the `'message'`, `'ping'`,
44-
* and `'pong'` events per microtask
42+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
43+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
44+
* multiple times in the same tick
4545
* @param {String} [options.binaryType=nodebuffer] The type for binary data
4646
* @param {Object} [options.extensions] An object containing the negotiated
4747
* extensions
@@ -54,8 +54,7 @@ class Receiver extends Writable {
5454
constructor(options = {}) {
5555
super();
5656

57-
this._allowMultipleEventsPerMicrotask =
58-
!!options.allowMultipleEventsPerMicrotask;
57+
this._allowSynchronousEvents = !!options.allowSynchronousEvents;
5958
this._binaryType = options.binaryType || BINARY_TYPES[0];
6059
this._extensions = options.extensions || {};
6160
this._isServer = !!options.isServer;
@@ -573,7 +572,7 @@ class Receiver extends Writable {
573572
// decompressed asynchronously, so there is no need to defer the event
574573
// as it will be emitted asynchronously anyway.
575574
//
576-
if (this._state === INFLATING || this._allowMultipleEventsPerMicrotask) {
575+
if (this._state === INFLATING || this._allowSynchronousEvents) {
577576
this.emit('message', data, true);
578577
this._state = GET_INFO;
579578
} else {
@@ -600,7 +599,7 @@ class Receiver extends Writable {
600599
return;
601600
}
602601

603-
if (this._state === INFLATING || this._allowMultipleEventsPerMicrotask) {
602+
if (this._state === INFLATING || this._allowSynchronousEvents) {
604603
this.emit('message', buf, false);
605604
this._state = GET_INFO;
606605
} else {
@@ -671,7 +670,7 @@ class Receiver extends Writable {
671670
return;
672671
}
673672

674-
if (this._allowMultipleEventsPerMicrotask) {
673+
if (this._allowSynchronousEvents) {
675674
this.emit(this._opcode === 0x09 ? 'ping' : 'pong', data);
676675
this._state = GET_INFO;
677676
} else {

lib/websocket-server.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class WebSocketServer extends EventEmitter {
2929
* Create a `WebSocketServer` instance.
3030
*
3131
* @param {Object} options Configuration options
32-
* @param {Boolean} [options.allowMultipleEventsPerMicrotask=false] Specifies
33-
* whether or not to process more than one of the `'message'`, `'ping'`,
34-
* and `'pong'` events per microtask
32+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
33+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
34+
* multiple times in the same tick
3535
* @param {Number} [options.backlog=511] The maximum length of the queue of
3636
* pending connections
3737
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
@@ -58,7 +58,7 @@ class WebSocketServer extends EventEmitter {
5858
super();
5959

6060
options = {
61-
allowMultipleEventsPerMicrotask: false,
61+
allowSynchronousEvents: false,
6262
maxPayload: 100 * 1024 * 1024,
6363
skipUTF8Validation: false,
6464
perMessageDeflate: false,
@@ -413,8 +413,7 @@ class WebSocketServer extends EventEmitter {
413413
socket.removeListener('error', socketOnError);
414414

415415
ws.setSocket(socket, head, {
416-
allowMultipleEventsPerMicrotask:
417-
this.options.allowMultipleEventsPerMicrotask,
416+
allowSynchronousEvents: this.options.allowSynchronousEvents,
418417
maxPayload: this.options.maxPayload,
419418
skipUTF8Validation: this.options.skipUTF8Validation
420419
});

lib/websocket.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ class WebSocket extends EventEmitter {
192192
* @param {Duplex} socket The network socket between the server and client
193193
* @param {Buffer} head The first packet of the upgraded stream
194194
* @param {Object} options Options object
195-
* @param {Boolean} [options.allowMultipleEventsPerMicrotask=false] Specifies
196-
* whether or not to process more than one of the `'message'`, `'ping'`,
197-
* and `'pong'` events per microtask
195+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
196+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
197+
* multiple times in the same tick
198198
* @param {Function} [options.generateMask] The function used to generate the
199199
* masking key
200200
* @param {Number} [options.maxPayload=0] The maximum allowed message size
@@ -204,7 +204,7 @@ class WebSocket extends EventEmitter {
204204
*/
205205
setSocket(socket, head, options) {
206206
const receiver = new Receiver({
207-
allowMultipleEventsPerMicrotask: options.allowMultipleEventsPerMicrotask,
207+
allowSynchronousEvents: options.allowSynchronousEvents,
208208
binaryType: this.binaryType,
209209
extensions: this._extensions,
210210
isServer: this._isServer,
@@ -622,9 +622,9 @@ module.exports = WebSocket;
622622
* @param {(String|URL)} address The URL to which to connect
623623
* @param {Array} protocols The subprotocols
624624
* @param {Object} [options] Connection options
625-
* @param {Boolean} [options.allowMultipleEventsPerMicrotask=false] Specifies
626-
* whether or not to process more than one of the `'message'`, `'ping'`,
627-
* and `'pong'` events per microtask
625+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether any
626+
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
627+
* times in the same tick
628628
* @param {Function} [options.finishRequest] A function which can be used to
629629
* customize the headers of each http request before it is sent
630630
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
@@ -649,7 +649,7 @@ module.exports = WebSocket;
649649
*/
650650
function initAsClient(websocket, address, protocols, options) {
651651
const opts = {
652-
allowMultipleEventsPerMicrotask: false,
652+
allowSynchronousEvents: false,
653653
protocolVersion: protocolVersions[1],
654654
maxPayload: 100 * 1024 * 1024,
655655
skipUTF8Validation: false,
@@ -1001,7 +1001,7 @@ function initAsClient(websocket, address, protocols, options) {
10011001
}
10021002

10031003
websocket.setSocket(socket, head, {
1004-
allowMultipleEventsPerMicrotask: opts.allowMultipleEventsPerMicrotask,
1004+
allowSynchronousEvents: opts.allowSynchronousEvents,
10051005
generateMask: opts.generateMask,
10061006
maxPayload: opts.maxPayload,
10071007
skipUTF8Validation: opts.skipUTF8Validation

test/receiver.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ describe('Receiver', () => {
443443
buf[i + 1] = 0x00;
444444
}
445445

446-
const receiver = new Receiver();
446+
const receiver = new Receiver({ allowSynchronousEvents: true });
447447
let counter = 0;
448448

449449
receiver.on('message', (data, isBinary) => {
@@ -1151,7 +1151,7 @@ describe('Receiver', () => {
11511151
receiver.write(Buffer.from('82008200', 'hex'));
11521152
});
11531153

1154-
it('honors the `allowMultipleEventsPerMicrotask` option', (done) => {
1154+
it('honors the `allowSynchronousEvents` option', (done) => {
11551155
const actual = [];
11561156
const expected = [
11571157
'1',
@@ -1179,7 +1179,7 @@ describe('Receiver', () => {
11791179
});
11801180
}
11811181

1182-
const receiver = new Receiver({ allowMultipleEventsPerMicrotask: true });
1182+
const receiver = new Receiver({ allowSynchronousEvents: true });
11831183

11841184
receiver.on('message', listener);
11851185
receiver.on('ping', listener);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy