Flush writes on resize

Fixes #5597
This commit is contained in:
Daniel Imms
2026-01-09 05:25:22 -08:00
parent 729a670043
commit bf7c95b6cc
3 changed files with 55 additions and 0 deletions
+32
View File
@@ -54,6 +54,38 @@ export class WriteBuffer extends Disposable {
this._didUserInput = true;
}
/**
* Flushes all pending writes synchronously. This is useful when you need to
* ensure all queued data is processed before performing an operation that
* depends upon everything being parsed like resize.
*
* Note: This is unreliable with async parser handlers as it does not wait for
* promises to resolve.
*/
public flushSync(): void {
// exit early if another sync write loop is active
if (this._isSyncWriting) {
return;
}
this._isSyncWriting = true;
// Process all pending chunks synchronously
let chunk: string | Uint8Array | undefined;
while (chunk = this._writeBuffer.shift()) {
this._action(chunk);
const cb = this._callbacks.shift();
if (cb) cb();
}
// Reset buffer state
this._pendingData = 0;
this._bufferOffset = 0x7FFFFFFF;
this._writeBuffer.length = 0;
this._callbacks.length = 0;
this._isSyncWriting = false;
}
/**
* @deprecated Unreliable, to be removed soon.
*/