| 118 | } |
| 119 | |
| 120 | function setPrivateThreadProps<T>(raw: T, worker: WorkerType, workerEvents: Observable<WorkerEvent>, terminate: () => Promise<void>): T & PrivateThreadProps { |
| 121 | const workerErrors = workerEvents |
| 122 | .filter(event => event.type === WorkerEventType.internalError) |
| 123 | .map(errorEvent => (errorEvent as WorkerInternalErrorEvent).error) |
| 124 | |
| 125 | // tslint:disable-next-line prefer-object-spread |
| 126 | return Object.assign(raw, { |
| 127 | [$errors]: workerErrors, |
| 128 | [$events]: workerEvents, |
| 129 | [$terminate]: terminate, |
| 130 | [$worker]: worker |
| 131 | }) |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Spawn a new thread. Takes a fresh worker instance, wraps it in a thin |