* Creates a new WriteQueue instance. * @param {Socket} netClient * @param {Encoder} encoder * @param {ClientOptions} options
(netClient, encoder, options)
| 182 | * @param {ClientOptions} options |
| 183 | */ |
| 184 | constructor(netClient, encoder, options) { |
| 185 | super(); |
| 186 | this.netClient = netClient; |
| 187 | this.encoder = encoder; |
| 188 | this.isRunning = false; |
| 189 | /** @type {Array<{operation: OperationState, callback: Function}>} */ |
| 190 | this.queue = []; |
| 191 | this.coalescingThreshold = options.socketOptions.coalescingThreshold; |
| 192 | this.error = null; |
| 193 | this.canWrite = true; |
| 194 | |
| 195 | // Listen to drain event that is going to be fired once |
| 196 | // the underlying buffer is empty |
| 197 | netClient.on('drain', () => { |
| 198 | this.canWrite = true; |
| 199 | this.run(); |
| 200 | }); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Enqueues a new request |