Skip to content

Commit

Permalink
fix: end buffer before piping it
Browse files Browse the repository at this point in the history
  • Loading branch information
invakid404 committed Nov 21, 2024
1 parent dead17c commit dead3ee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/generator/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const run = async <T,>(
}),
);

const end = (stream: Writable) =>
new Promise<void>((resolve) => stream.end(() => resolve()));

const deferredWrites: string[] = [];

// NOTE: if we're running in a nested context, we want to lift deferred
Expand All @@ -50,10 +53,12 @@ export const run = async <T,>(
// NOTE: in order to avoid the output being dependent on the write order,
// deferred writes are sorted before written to the output
await write(deferredWrites.sort().join("\n"), buffer);
await end(buffer);

await pipeline(buffer, output, { end: false });
}

await new Promise<void>((resolve) => output.end(() => resolve()));
await end(output);

return result;
};
Expand Down

0 comments on commit dead3ee

Please sign in to comment.