Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function startServer() {
return (data) => {
s += data;
if (!sender) {
sender = setTimeout(() => {
sender = queueMicrotask(() => {
socket.send(s);
s = '';
sender = null;
Expand All @@ -103,7 +103,7 @@ function startServer() {
buffer.push(data);
length += data.length;
if (!sender) {
sender = setTimeout(() => {
sender = queueMicrotask(() => {
socket.send(Buffer.concat(buffer, length));
buffer = [];
sender = null;
Expand Down
4 changes: 2 additions & 2 deletions src/common/input/WriteBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class WriteBuffer {
// schedule chunk processing for next event loop run
if (!this._writeBuffer.length) {
this._bufferOffset = 0;
setTimeout(() => this._innerWrite());
queueMicrotask(() => this._innerWrite());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be safe with queueMicrotask - reason: this code path is only entered, if the write queue was empty before, which guarantees, that there happened a screen refresh before.

}

this._pendingData += data.length;
Expand Down Expand Up @@ -217,7 +217,7 @@ export class WriteBuffer {
this._callbacks = this._callbacks.slice(this._bufferOffset);
this._bufferOffset = 0;
}
setTimeout(() => this._innerWrite());
queueMicrotask(() => this._innerWrite());
Copy link
Member

@jerch jerch Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure about queueMicrotask here - imho this will skip any screen refreshs in between, if the write queue never drops empty? (This edge case might be provokable by tiny messages at sync promisified term.write calls while the write queue never drops empty...)

There are more edge cases linked to direct microtask usage - imho chrome and firefox prioritize them differently (dont remember the details atm).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps. You're right, will fix

There are more edge cases linked to direct microtask usage - imho chrome and firefox prioritize them differently (dont remember the details atm).

I didn't test in Firefox but this should only matter if queueMicrotask ends up slower than setTimeout which I think would be against the spec?

} else {
this._writeBuffer.length = 0;
this._callbacks.length = 0;
Expand Down