Skip to content

Commit

Permalink
feat(cdk): async waiting for deploy events
Browse files Browse the repository at this point in the history
  • Loading branch information
kedrzu committed Apr 3, 2024
1 parent db56638 commit 4be5a5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/aws-cdk/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
}
}
}
Expand All @@ -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({
Expand All @@ -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');
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions packages/aws-cdk/src/Stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export type StackHandler = () => Promise<void>;

export class Stack extends cdk.Stack {
private readonly eventEmitter = createEventEmitter<StackEvents>();
private readonly tasks: StackHandler[] = [];

public deployResult: DeployStackResult | undefined;

Expand All @@ -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);
}
}

0 comments on commit 4be5a5f

Please sign in to comment.