(result: unknown)
| 110 | } |
| 111 | |
| 112 | function reportSuccess(result: unknown) { |
| 113 | if (isMainThread) { |
| 114 | throw new Error('Child can only be used on a forked process'); |
| 115 | } |
| 116 | |
| 117 | try { |
| 118 | parentPort!.postMessage([PARENT_MESSAGE_OK, result]); |
| 119 | } catch (error) { |
| 120 | let resolvedError = error; |
| 121 | // Try to handle https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal |
| 122 | // for `symbols` and `functions` |
| 123 | if (isDataCloneError(error)) { |
| 124 | try { |
| 125 | parentPort!.postMessage([PARENT_MESSAGE_OK, packMessage(result)]); |
| 126 | return; |
| 127 | } catch (secondTryError) { |
| 128 | resolvedError = secondTryError; |
| 129 | } |
| 130 | } |
| 131 | // Handling it here to avoid unhandled rejection |
| 132 | // which is hard to distinguish on the parent side |
| 133 | reportClientError(resolvedError as Error); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function reportClientError(error: Error) { |
| 138 | return reportError(error, PARENT_MESSAGE_CLIENT_ERROR); |
no test coverage detected