Skip to content

Commit 6cd2e4e

Browse files
refactor: remove the packetBuffer array
The parser#encode() method is now synchronous, so the packetBuffer array is useless.
1 parent c07b91d commit 6cd2e4e

File tree

3 files changed

+6
-69
lines changed

3 files changed

+6
-69
lines changed

build/manager.d.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export declare class Manager extends Emitter {
1515
private _reconnectionDelayMax;
1616
private _timeout;
1717
private connecting;
18-
private encoding;
19-
private packetBuffer;
2018
private encoder;
2119
private decoder;
2220
private engine;
@@ -141,13 +139,6 @@ export declare class Manager extends Emitter {
141139
* @api private
142140
*/
143141
packet(packet: any): void;
144-
/**
145-
* If packet buffer is non-empty, begins encoding the
146-
* next packet in line.
147-
*
148-
* @api private
149-
*/
150-
processPacketQueue(): void;
151142
/**
152143
* Clean up transport subscriptions and packet buffer.
153144
*

build/manager.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Manager extends component_emitter_1.default {
4949
this.nsps = {};
5050
this.subs = [];
5151
this.connecting = [];
52-
this.packetBuffer = [];
5352
if (uri && "object" === typeof uri) {
5453
opts = uri;
5554
uri = undefined;
@@ -70,7 +69,6 @@ class Manager extends component_emitter_1.default {
7069
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
7170
this.readyState = "closed";
7271
this.uri = uri;
73-
this.encoding = false;
7472
const _parser = opts.parser || parser;
7573
this.encoder = new _parser.Encoder();
7674
this.decoder = new _parser.Decoder();
@@ -399,31 +397,9 @@ class Manager extends component_emitter_1.default {
399397
debug("writing packet %j", packet);
400398
if (packet.query && packet.type === 0)
401399
packet.nsp += "?" + packet.query;
402-
if (!this.encoding) {
403-
// encode, then write to engine with result
404-
this.encoding = true;
405-
const encodedPackets = this.encoder.encode(packet);
406-
for (let i = 0; i < encodedPackets.length; i++) {
407-
this.engine.write(encodedPackets[i], packet.options);
408-
}
409-
this.encoding = false;
410-
this.processPacketQueue();
411-
}
412-
else {
413-
// add packet to the queue
414-
this.packetBuffer.push(packet);
415-
}
416-
}
417-
/**
418-
* If packet buffer is non-empty, begins encoding the
419-
* next packet in line.
420-
*
421-
* @api private
422-
*/
423-
processPacketQueue() {
424-
if (this.packetBuffer.length > 0 && !this.encoding) {
425-
const pack = this.packetBuffer.shift();
426-
this.packet(pack);
400+
const encodedPackets = this.encoder.encode(packet);
401+
for (let i = 0; i < encodedPackets.length; i++) {
402+
this.engine.write(encodedPackets[i], packet.options);
427403
}
428404
}
429405
/**
@@ -438,8 +414,6 @@ class Manager extends component_emitter_1.default {
438414
const sub = this.subs.shift();
439415
sub.destroy();
440416
}
441-
this.packetBuffer = [];
442-
this.encoding = false;
443417
this.decoder.destroy();
444418
}
445419
/**

lib/manager.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export class Manager extends Emitter {
3434
private _timeout: any;
3535

3636
private connecting: Array<Socket> = [];
37-
private encoding: boolean;
38-
private packetBuffer: Array<any> = [];
3937
private encoder: Encoder;
4038
private decoder: Decoder;
4139
private engine: any;
@@ -71,7 +69,6 @@ export class Manager extends Emitter {
7169
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
7270
this.readyState = "closed";
7371
this.uri = uri;
74-
this.encoding = false;
7572
const _parser = opts.parser || parser;
7673
this.encoder = new _parser.Encoder();
7774
this.decoder = new _parser.Decoder();
@@ -432,31 +429,9 @@ export class Manager extends Emitter {
432429
debug("writing packet %j", packet);
433430
if (packet.query && packet.type === 0) packet.nsp += "?" + packet.query;
434431

435-
if (!this.encoding) {
436-
// encode, then write to engine with result
437-
this.encoding = true;
438-
const encodedPackets = this.encoder.encode(packet);
439-
for (let i = 0; i < encodedPackets.length; i++) {
440-
this.engine.write(encodedPackets[i], packet.options);
441-
}
442-
this.encoding = false;
443-
this.processPacketQueue();
444-
} else {
445-
// add packet to the queue
446-
this.packetBuffer.push(packet);
447-
}
448-
}
449-
450-
/**
451-
* If packet buffer is non-empty, begins encoding the
452-
* next packet in line.
453-
*
454-
* @api private
455-
*/
456-
processPacketQueue() {
457-
if (this.packetBuffer.length > 0 && !this.encoding) {
458-
const pack = this.packetBuffer.shift();
459-
this.packet(pack);
432+
const encodedPackets = this.encoder.encode(packet);
433+
for (let i = 0; i < encodedPackets.length; i++) {
434+
this.engine.write(encodedPackets[i], packet.options);
460435
}
461436
}
462437

@@ -474,9 +449,6 @@ export class Manager extends Emitter {
474449
sub.destroy();
475450
}
476451

477-
this.packetBuffer = [];
478-
this.encoding = false;
479-
480452
this.decoder.destroy();
481453
}
482454

0 commit comments

Comments
 (0)