Skip to content

Commit

Permalink
refactor: remove the packetBuffer array
Browse files Browse the repository at this point in the history
The parser#encode() method is now synchronous, so the packetBuffer
array is useless.
  • Loading branch information
darrachequesne committed Oct 12, 2020
1 parent c07b91d commit 6cd2e4e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 69 deletions.
9 changes: 0 additions & 9 deletions build/manager.d.ts
Expand Up @@ -15,8 +15,6 @@ export declare class Manager extends Emitter {
private _reconnectionDelayMax;
private _timeout;
private connecting;
private encoding;
private packetBuffer;
private encoder;
private decoder;
private engine;
Expand Down Expand Up @@ -141,13 +139,6 @@ export declare class Manager extends Emitter {
* @api private
*/
packet(packet: any): void;
/**
* If packet buffer is non-empty, begins encoding the
* next packet in line.
*
* @api private
*/
processPacketQueue(): void;
/**
* Clean up transport subscriptions and packet buffer.
*
Expand Down
32 changes: 3 additions & 29 deletions build/manager.js
Expand Up @@ -49,7 +49,6 @@ class Manager extends component_emitter_1.default {
this.nsps = {};
this.subs = [];
this.connecting = [];
this.packetBuffer = [];
if (uri && "object" === typeof uri) {
opts = uri;
uri = undefined;
Expand All @@ -70,7 +69,6 @@ class Manager extends component_emitter_1.default {
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
this.readyState = "closed";
this.uri = uri;
this.encoding = false;
const _parser = opts.parser || parser;
this.encoder = new _parser.Encoder();
this.decoder = new _parser.Decoder();
Expand Down Expand Up @@ -399,31 +397,9 @@ class Manager extends component_emitter_1.default {
debug("writing packet %j", packet);
if (packet.query && packet.type === 0)
packet.nsp += "?" + packet.query;
if (!this.encoding) {
// encode, then write to engine with result
this.encoding = true;
const encodedPackets = this.encoder.encode(packet);
for (let i = 0; i < encodedPackets.length; i++) {
this.engine.write(encodedPackets[i], packet.options);
}
this.encoding = false;
this.processPacketQueue();
}
else {
// add packet to the queue
this.packetBuffer.push(packet);
}
}
/**
* If packet buffer is non-empty, begins encoding the
* next packet in line.
*
* @api private
*/
processPacketQueue() {
if (this.packetBuffer.length > 0 && !this.encoding) {
const pack = this.packetBuffer.shift();
this.packet(pack);
const encodedPackets = this.encoder.encode(packet);
for (let i = 0; i < encodedPackets.length; i++) {
this.engine.write(encodedPackets[i], packet.options);
}
}
/**
Expand All @@ -438,8 +414,6 @@ class Manager extends component_emitter_1.default {
const sub = this.subs.shift();
sub.destroy();
}
this.packetBuffer = [];
this.encoding = false;
this.decoder.destroy();
}
/**
Expand Down
34 changes: 3 additions & 31 deletions lib/manager.ts
Expand Up @@ -34,8 +34,6 @@ export class Manager extends Emitter {
private _timeout: any;

private connecting: Array<Socket> = [];
private encoding: boolean;
private packetBuffer: Array<any> = [];
private encoder: Encoder;
private decoder: Decoder;
private engine: any;
Expand Down Expand Up @@ -71,7 +69,6 @@ export class Manager extends Emitter {
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
this.readyState = "closed";
this.uri = uri;
this.encoding = false;
const _parser = opts.parser || parser;
this.encoder = new _parser.Encoder();
this.decoder = new _parser.Decoder();
Expand Down Expand Up @@ -432,31 +429,9 @@ export class Manager extends Emitter {
debug("writing packet %j", packet);
if (packet.query && packet.type === 0) packet.nsp += "?" + packet.query;

if (!this.encoding) {
// encode, then write to engine with result
this.encoding = true;
const encodedPackets = this.encoder.encode(packet);
for (let i = 0; i < encodedPackets.length; i++) {
this.engine.write(encodedPackets[i], packet.options);
}
this.encoding = false;
this.processPacketQueue();
} else {
// add packet to the queue
this.packetBuffer.push(packet);
}
}

/**
* If packet buffer is non-empty, begins encoding the
* next packet in line.
*
* @api private
*/
processPacketQueue() {
if (this.packetBuffer.length > 0 && !this.encoding) {
const pack = this.packetBuffer.shift();
this.packet(pack);
const encodedPackets = this.encoder.encode(packet);
for (let i = 0; i < encodedPackets.length; i++) {
this.engine.write(encodedPackets[i], packet.options);
}
}

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

this.packetBuffer = [];
this.encoding = false;

this.decoder.destroy();
}

Expand Down

0 comments on commit 6cd2e4e

Please sign in to comment.