|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 | import { experimental, json, logging } from '@angular-devkit/core';
|
9 |
| -import { Subscription } from 'rxjs'; |
10 |
| -import { first, ignoreElements, map, shareReplay } from 'rxjs/operators'; |
| 9 | +import { EMPTY, Subscription } from 'rxjs'; |
| 10 | +import { catchError, first, ignoreElements, map, share, shareReplay, tap } from 'rxjs/operators'; |
11 | 11 | import {
|
12 | 12 | BuilderInfo,
|
13 | 13 | BuilderInput,
|
@@ -60,46 +60,55 @@ export async function scheduleByName(
|
60 | 60 | if (event.kind === experimental.jobs.JobOutboundMessageKind.Start) {
|
61 | 61 | job.input.next(message);
|
62 | 62 | }
|
63 |
| - }); |
| 63 | + }, () => {}); |
64 | 64 | } else {
|
65 | 65 | job.input.next(message);
|
66 | 66 | }
|
67 | 67 |
|
68 | 68 | const logChannelSub = job.getChannel<logging.LogEntry>('log').subscribe(entry => {
|
69 | 69 | logger.next(entry);
|
70 |
| - }); |
| 70 | + }, () => {}); |
71 | 71 |
|
72 |
| - const s = job.outboundBus.subscribe( |
73 |
| - undefined, |
74 |
| - undefined, |
75 |
| - () => { |
| 72 | + const s = job.outboundBus.subscribe({ |
| 73 | + error() {}, |
| 74 | + complete() { |
76 | 75 | s.unsubscribe();
|
77 | 76 | logChannelSub.unsubscribe();
|
78 | 77 | if (stateSubscription) {
|
79 | 78 | stateSubscription.unsubscribe();
|
80 | 79 | }
|
81 | 80 | },
|
82 |
| - ); |
| 81 | + }); |
83 | 82 | const output = job.output.pipe(
|
84 | 83 | map(output => ({
|
85 | 84 | ...output,
|
86 | 85 | ...options.target ? { target: options.target } : 0,
|
87 | 86 | info,
|
88 | 87 | } as BuilderOutput)),
|
| 88 | + shareReplay(), |
89 | 89 | );
|
90 | 90 |
|
| 91 | + // Start the builder. |
| 92 | + output.pipe(first()).subscribe({ |
| 93 | + error() {}, |
| 94 | + }); |
| 95 | + |
91 | 96 | return {
|
92 | 97 | id,
|
93 | 98 | info,
|
94 |
| - result: output.pipe(first()).toPromise(), |
| 99 | + // This is a getter so that it always returns the next output, and not the same one. |
| 100 | + get result() { return output.pipe(first()).toPromise(); }, |
95 | 101 | output,
|
96 | 102 | progress: job.getChannel<BuilderProgressReport>('progress', progressSchema).pipe(
|
97 | 103 | shareReplay(1),
|
98 | 104 | ),
|
99 | 105 | stop() {
|
100 | 106 | job.stop();
|
101 | 107 |
|
102 |
| - return output.pipe(ignoreElements()).toPromise(); |
| 108 | + return job.outboundBus.pipe( |
| 109 | + ignoreElements(), |
| 110 | + catchError(() => EMPTY), |
| 111 | + ).toPromise(); |
103 | 112 | },
|
104 | 113 | };
|
105 | 114 | }
|
|
0 commit comments