From 4be5a5f318cd85a494ef16bdaff09a41b3f6f269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99drzy=C5=84ski?= Date: Wed, 3 Apr 2024 13:35:38 +0200 Subject: [PATCH] feat(cdk): async waiting for deploy events --- packages/aws-cdk/src/App.ts | 8 ++++---- packages/aws-cdk/src/Stack.ts | 11 +---------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/aws-cdk/src/App.ts b/packages/aws-cdk/src/App.ts index 65eb5f8..c723ac2 100644 --- a/packages/aws-cdk/src/App.ts +++ b/packages/aws-cdk/src/App.ts @@ -98,7 +98,7 @@ export class App extends cdk.App { consola.info(`Deploying stack ${chalk.green(stackName)}`); if (stack instanceof Stack) { - stack.$.emit('deploy:start'); + await stack.$.emitAsync('deploy:start'); } const deployment = await this.deployments.deployStack({ @@ -117,7 +117,7 @@ export class App extends cdk.App { deployment.outputs, ); if (stack instanceof Stack) { - stack?.$.emit('deploy:finished', deployment); + await stack?.$.emitAsync('deploy:finished', deployment); } } } @@ -133,7 +133,7 @@ export class App extends cdk.App { consola.info(`Destroying stack ${chalk.green(stackName)}`); if (stack instanceof Stack) { - stack.$.emit('destroy:start'); + await stack.$.emitAsync('destroy:start'); } await this.deployments.destroyStack({ @@ -143,7 +143,7 @@ export class App extends cdk.App { consola.success(`Successfully destroyed stack ${chalk.green(stackName)}`); if (stack instanceof Stack) { - stack.$.emit('destroy:finished'); + await stack.$.emitAsync('destroy:finished'); } } } diff --git a/packages/aws-cdk/src/Stack.ts b/packages/aws-cdk/src/Stack.ts index 5599e5b..7f24599 100644 --- a/packages/aws-cdk/src/Stack.ts +++ b/packages/aws-cdk/src/Stack.ts @@ -22,7 +22,6 @@ export type StackHandler = () => Promise; export class Stack extends cdk.Stack { private readonly eventEmitter = createEventEmitter(); - private readonly tasks: StackHandler[] = []; public deployResult: DeployStackResult | undefined; @@ -49,14 +48,6 @@ export class Stack extends cdk.Stack { /** Internal */ public readonly $ = { emit: this.eventEmitter.emit, - execute: async () => { - for (const task of this.tasks) { - await task(); - } - }, + emitAsync: this.eventEmitter.emitAsync, }; - - public enqueue(handler: StackHandler) { - this.tasks.push(handler); - } }