Skip to content

Commit

Permalink
Await promises separate from queueing
Browse files Browse the repository at this point in the history
  • Loading branch information
relm923 committed Jul 31, 2022
1 parent d73a51a commit 7935c0b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,31 @@ export class CdkToolkit {
.filter((id) => !id.endsWith('.assets'))
.every((id) => !stacksAwaitingDeploy[id]);

const stackDeployPromises: Promise<void>[] = [];

const enqueueStackDeploys = async () => {
await Promise.all(stacks.map(async (stack) => {
stacks.forEach(async (stack) => {
if (isStackUnblocked(stack)) {
// Find current index due to stacks list changing within loop
const index = stacks.indexOf(stack);
stacks.splice(index, 1);

return queue.add(async () => {
stackDeployPromises.push(queue.add(async () => {
await deployStack(stack);
await enqueueStackDeploys();
});
}));
}
}));
});
};

await enqueueStackDeploys();
await queue.onIdle();
try {
await enqueueStackDeploys();
await Promise.all(stackDeployPromises);
await queue.onIdle();
} catch (e) {
error('\n ❌ Deployment failed: %s', e);
throw e;
}
}

public async watch(options: WatchOptions) {
Expand Down

0 comments on commit 7935c0b

Please sign in to comment.