mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
refactor(workers): share bounded JSON line writes (#14585)
This commit is contained in:
1 parent
6e771da08e
commit
1dfd0e5fb4
3 files changed
+26
-22
No files matched your search
@@ -0,0 +1,14 @@
|
||||
/** Write one JSON line and wait for stdout to accept it. */
|
||||
export const writeWorkerControlFrame = (
|
||||
value: unknown,
|
||||
limit: number,
|
||||
limitMessage: string,
|
||||
): Promise<void> => {
|
||||
const frame = `${JSON.stringify(value)}\n`;
|
||||
if (Buffer.byteLength(frame) > limit) throw new RangeError(limitMessage);
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
process.stdout.write(frame, (error) =>
|
||||
error === null || error === undefined ? resolve() : reject(error),
|
||||
);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user