Skip to content

Commit

Permalink
chore: rename buffered renderer properties to remove prefix
Browse files Browse the repository at this point in the history
Removes the `__` prefix of the private properties to match the
conventions used elsewhere in the repo.
  • Loading branch information
43081j committed Apr 1, 2024
1 parent 2ca10a9 commit 2eb2f1a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/astro/src/runtime/server/render/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,34 @@ export function renderElement(
}

const noop = () => {};

/**
* Renders into a buffer until `renderToFinalDestination` is called (which
* flushes the buffer)
*/
class BufferedRenderer implements RenderDestination {
private __chunks: RenderDestinationChunk[] = [];
private __renderPromise: Promise<void> | void;
private __destination?: RenderDestination;
private chunks: RenderDestinationChunk[] = [];
private renderPromise: Promise<void> | void;
private destination?: RenderDestination;

public constructor(bufferRenderFunction: RenderFunction) {
this.__renderPromise = bufferRenderFunction(this);
this.renderPromise = bufferRenderFunction(this);
// Catch here in case it throws before `renderToFinalDestination` is called,
// to prevent an unhandled rejection.
Promise.resolve(this.__renderPromise).catch(noop);
Promise.resolve(this.renderPromise).catch(noop);
}

public write(chunk: RenderDestinationChunk): void {
if (this.__destination) {
this.__destination.write(chunk);
if (this.destination) {
this.destination.write(chunk);
} else {
this.__chunks.push(chunk);
this.chunks.push(chunk);
}
}

public async renderToFinalDestination(destination: RenderDestination) {
// Write the buffered chunks to the real destination
for (const chunk of this.__chunks) {
for (const chunk of this.chunks) {
destination.write(chunk);
}

Expand All @@ -182,10 +187,10 @@ class BufferedRenderer implements RenderDestination {
// (Unsure how this affects on limited memory machines)

// Re-assign the real destination so `instance.render` will continue and write to the new destination
this.__destination = destination;
this.destination = destination;

// Wait for render to finish entirely
await this.__renderPromise;
await this.renderPromise;
}
}

Expand Down

0 comments on commit 2eb2f1a

Please sign in to comment.