diff --git a/goldens/public-api/angular_devkit/architect/index.md b/goldens/public-api/angular_devkit/architect/index.md index 70cdd28738ab..1dc0c183e10e 100644 --- a/goldens/public-api/angular_devkit/architect/index.md +++ b/goldens/public-api/angular_devkit/architect/index.md @@ -451,6 +451,8 @@ export function scheduleTargetAndForget(context: BuilderContext, target: Target, // @public interface SimpleJobHandlerContext extends JobHandlerContext { + // (undocumented) + addTeardown(teardown: () => Promise | void): void; // (undocumented) createChannel: (name: string) => Observer; // (undocumented) diff --git a/packages/angular_devkit/architect/src/create-builder.ts b/packages/angular_devkit/architect/src/create-builder.ts index 2f7f8c85d9df..d832c7e67755 100644 --- a/packages/angular_devkit/architect/src/create-builder.ts +++ b/packages/angular_devkit/architect/src/create-builder.ts @@ -47,9 +47,8 @@ export function createBuilder PromiseLike | void> = []; - let tearingDown = false; let current = 0; let status = ''; let total = 1; @@ -83,18 +82,8 @@ export function createBuilder { switch (i.kind) { - case JobInboundMessageKind.Stop: - // Run teardown logic then complete. - tearingDown = true; - Promise.all(teardownLogics.map((fn) => fn() || Promise.resolve())).then( - () => observer.complete(), - (err) => observer.error(err), - ); - break; case JobInboundMessageKind.Input: - if (!tearingDown) { - onInput(i.value); - } + onInput(i.value); break; } }); @@ -209,9 +198,7 @@ export function createBuilder Promise | void): void { - teardownLogics.push(teardown); - }, + addTeardown, }; context.reportRunning(); diff --git a/packages/angular_devkit/architect/src/jobs/create-job-handler.ts b/packages/angular_devkit/architect/src/jobs/create-job-handler.ts index 36952e56a2ff..531c21e5fdc5 100644 --- a/packages/angular_devkit/architect/src/jobs/create-job-handler.ts +++ b/packages/angular_devkit/architect/src/jobs/create-job-handler.ts @@ -44,6 +44,7 @@ export interface SimpleJobHandlerContext< > extends JobHandlerContext { createChannel: (name: string) => Observer; input: Observable; + addTeardown(teardown: () => Promise | void): void; } /** @@ -72,6 +73,8 @@ export function createJobHandler(); let subscription: Subscription; + const teardownLogics: Array<() => PromiseLike | void> = []; + let tearingDown = false; return new Observable>((subject) => { function complete() { @@ -91,13 +94,22 @@ export function createJobHandler fn())).then( + () => complete(), + () => complete(), + ); + } else { + complete(); + } break; case JobInboundMessageKind.Input: - inputChannel.next(message.value); + if (!tearingDown) { + inputChannel.next(message.value); + } break; } }); @@ -108,6 +120,9 @@ export function createJobHandler = { ...context, input: inputChannel.asObservable(), + addTeardown(teardown: () => Promise | void): void { + teardownLogics.push(teardown); + }, createChannel(name: string) { if (channels.has(name)) { throw new ChannelAlreadyExistException(name);