Skip to content

Commit

Permalink
feat(async-ssr-manager): async render inside renderUntilCompleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Kalinin authored and nikmilson committed Jan 14, 2022
1 parent deeefd0 commit 99b80ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/async-ssr-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface AsyncSsrManagerV1 {
*
* @param render A render function that is called for each render pass.
*/
renderUntilCompleted(render: () => string): Promise<string>;
renderUntilCompleted(render: () => Promise<string> | string): Promise<string>;

/**
* This method is intended for consumers, i.e. Feature Apps and Feature
Expand Down
12 changes: 8 additions & 4 deletions packages/async-ssr-manager/src/internal/async-ssr-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class AsyncSsrManager implements AsyncSsrManagerV1 {
private readonly timeout?: number
) {}

public async renderUntilCompleted(render: () => string): Promise<string> {
public async renderUntilCompleted(
render: () => Promise<string> | string
): Promise<string> {
const renderPromise = this.renderingLoop(render);

if (typeof this.timeout !== 'number') {
Expand All @@ -36,8 +38,10 @@ export class AsyncSsrManager implements AsyncSsrManagerV1 {
this.asyncOperations.add(asyncOperation);
}

private async renderingLoop(render: () => string): Promise<string> {
let html = render();
private async renderingLoop(
render: () => Promise<string> | string
): Promise<string> {
let html = await render();

while (this.asyncOperations.size > 0) {
while (this.asyncOperations.size > 0) {
Expand All @@ -54,7 +58,7 @@ export class AsyncSsrManager implements AsyncSsrManagerV1 {
await Promise.all(asyncOperationsSnapshot);
}

html = render();
html = await render();
}

return html;
Expand Down

0 comments on commit 99b80ce

Please sign in to comment.