diff --git a/src/client.js b/src/client.js index a173ce92..37eb8f52 100644 --- a/src/client.js +++ b/src/client.js @@ -57,7 +57,8 @@ module.exports = class IrcClient extends EventEmitter { sasl_disconnect_on_fail: false, transport: default_transport, websocket_protocol: 'text.ircv3.net', - serialize_writes: false + serialize_writes: false, + serialized_writes_flood_protect_ms: 100 }; const props = Object.keys(defaults); diff --git a/src/transports/net.js b/src/transports/net.js index 3a6de213..6262f6a2 100644 --- a/src/transports/net.js +++ b/src/transports/net.js @@ -14,6 +14,8 @@ const SOCK_DISCONNECTED = 0; const SOCK_CONNECTING = 1; const SOCK_CONNECTED = 2; +const FLOOD_PROTECT_WAIT_MS = 100; + module.exports = class Connection extends EventEmitter { constructor(options) { super(); @@ -91,6 +93,7 @@ module.exports = class Connection extends EventEmitter { this.incoming_buffer = Buffer.from(''); if (options.serialize_writes) { + const flood_protect_wait_ms = options.serialized_writes_flood_protect_ms || FLOOD_PROTECT_WAIT_MS; this.write_queue = []; this.write_queue_servicer = () => { if (this.write_queue.length) { @@ -100,7 +103,7 @@ module.exports = class Connection extends EventEmitter { } this.write_queue = this.write_queue.slice(1); - process.nextTick(this.write_queue_servicer); + setTimeout(this.write_queue_servicer, flood_protect_wait_ms); }); } };