@@ -30,6 +30,7 @@ export class PoolRunner {
|
30 | 30 | |
31 | 31 | private _state: RunnerState = RunnerState.IDLE |
32 | 32 | private _operationLock: DeferPromise<void> | null = null |
| 33 | +private _terminatePromise: DeferPromise<void> = createDefer() |
33 | 34 | |
34 | 35 | private _eventEmitter: EventEmitter<{ |
35 | 36 | message: [WorkerResponse] |
@@ -44,6 +45,10 @@ export class PoolRunner {
|
44 | 45 | return this._state === RunnerState.STOPPED |
45 | 46 | } |
46 | 47 | |
| 48 | +public waitForTerminated(): Promise<void> { |
| 49 | +return this._terminatePromise |
| 50 | +} |
| 51 | + |
47 | 52 | public get isStarted(): boolean { |
48 | 53 | return this._state === RunnerState.STARTED |
49 | 54 | } |
@@ -58,7 +63,11 @@ export class PoolRunner {
|
58 | 63 | }), |
59 | 64 | { |
60 | 65 | eventNames: ['onCancel'], |
61 | | -post: request => this.postMessage(request), |
| 66 | +post: (request) => { |
| 67 | +if (this._state !== RunnerState.STOPPING && this._state !== RunnerState.STOPPED) { |
| 68 | +this.postMessage(request) |
| 69 | +} |
| 70 | +}, |
62 | 71 | on: callback => this._eventEmitter.on('rpc', callback), |
63 | 72 | timeout: -1, |
64 | 73 | }, |
@@ -199,6 +208,7 @@ export class PoolRunner {
|
199 | 208 | finally { |
200 | 209 | this._operationLock.resolve() |
201 | 210 | this._operationLock = null |
| 211 | +this._terminatePromise.resolve() |
202 | 212 | } |
203 | 213 | } |
204 | 214 | |
|