From ca3524b9e36e7bf0d12764bb4d3090da1b1b6cb2 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Wed, 30 Sep 2020 21:30:58 -0400 Subject: [PATCH] sheet: wait for drain on writing entries --- tools/sheet/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/sheet/index.ts b/tools/sheet/index.ts index 7ca3caf6..ec53e7dc 100644 --- a/tools/sheet/index.ts +++ b/tools/sheet/index.ts @@ -40,7 +40,13 @@ const proc = cp.spawn("magick", [ // Write one at a time to avoid "malloc(): corrupted top size" error for (const entry of sheet.entries) { - proc.stdin.write(entry + "\n"); + if (!proc.stdin.write(entry + "\n")) { + // imagick doesn't like it when it receives the input too fast. This + // seems to avoid a realloc() invalid next size error. + await new Promise(resolve => { + proc.stdin.once('drain', resolve); + }); + } } proc.stdin.end();