Skip to content

Commit c05988c

Browse files
committed
Revert "use FixedQueue"
This reverts commit 0e415b2.
1 parent 826c84c commit c05988c

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

lib/web/websocket/sender.js

+30-12
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
const { WebsocketFrameSend } = require('./frame')
44
const { opcodes, sendHints } = require('./constants')
5-
const FixedQueue = require('../../dispatcher/fixed-queue')
65

76
/** @type {typeof Uint8Array} */
87
const FastBuffer = Buffer[Symbol.species]
98

109
/**
11-
* @typedef {object} QueueNode
10+
* @typedef {object} SendQueueNode
11+
* @property {SendQueueNode | null} next
1212
* @property {Promise<void> | null} promise
1313
* @property {((...args: any[]) => any)} callback
1414
* @property {Buffer | null} frame
1515
*/
1616

1717
class SendQueue {
1818
/**
19-
* @type {FixedQueue | null}
19+
* @type {SendQueueNode | null}
2020
*/
21-
#queue = null
21+
#head = null
22+
/**
23+
* @type {SendQueueNode | null}
24+
*/
25+
#tail = null
2226

2327
/**
2428
* @type {boolean}
@@ -39,19 +43,24 @@ class SendQueue {
3943
// fast-path
4044
this.#socket.write(frame, cb)
4145
} else {
42-
/** @type {QueueNode} */
46+
/** @type {SendQueueNode} */
4347
const node = {
48+
next: null,
4449
promise: null,
4550
callback: cb,
4651
frame
4752
}
48-
(this.#queue ??= new FixedQueue()).push(node)
53+
if (this.#tail !== null) {
54+
this.#tail.next = node
55+
}
56+
this.#tail = node
4957
}
5058
return
5159
}
5260

53-
/** @type {QueueNode} */
61+
/** @type {SendQueueNode} */
5462
const node = {
63+
next: null,
5564
promise: item.arrayBuffer().then((ab) => {
5665
node.promise = null
5766
node.frame = createFrame(ab, hint)
@@ -60,7 +69,13 @@ class SendQueue {
6069
frame: null
6170
}
6271

63-
(this.#queue ??= new FixedQueue()).push(node)
72+
if (this.#tail === null) {
73+
this.#tail = node
74+
}
75+
76+
if (this.#head === null) {
77+
this.#head = node
78+
}
6479

6580
if (!this.#running) {
6681
this.#run()
@@ -69,10 +84,9 @@ class SendQueue {
6984

7085
async #run () {
7186
this.#running = true
72-
/** @type {FixedQueue} */
73-
const queue = this.#queue
74-
while (!queue.isEmpty()) {
75-
const node = queue.shift()
87+
/** @type {SendQueueNode | null} */
88+
let node = this.#head
89+
while (node !== null) {
7690
// wait pending promise
7791
if (node.promise !== null) {
7892
await node.promise
@@ -81,7 +95,11 @@ class SendQueue {
8195
this.#socket.write(node.frame, node.callback)
8296
// cleanup
8397
node.callback = node.frame = null
98+
// set next
99+
node = node.next
84100
}
101+
this.#head = null
102+
this.#tail = null
85103
this.#running = false
86104
}
87105
}

0 commit comments

Comments
 (0)