(jobUID, fn, args)
| 402 | } |
| 403 | } |
| 404 | function runFunction(jobUID, fn, args) { |
| 405 | return __awaiter(this, void 0, void 0, function* () { |
| 406 | let syncResult; |
| 407 | try { |
| 408 | syncResult = fn(...args); |
| 409 | } catch (error) { |
| 410 | return postJobErrorMessage(jobUID, error); |
| 411 | } |
| 412 | const resultType = isObservable(syncResult) ? 'observable' : 'promise'; |
| 413 | postJobStartMessage(jobUID, resultType); |
| 414 | if (isObservable(syncResult)) { |
| 415 | const subscription = syncResult.subscribe( |
| 416 | (value) => |
| 417 | postJobResultMessage(jobUID, false, common_1.serialize(value)), |
| 418 | (error) => { |
| 419 | postJobErrorMessage(jobUID, common_1.serialize(error)); |
| 420 | activeSubscriptions.delete(jobUID); |
| 421 | }, |
| 422 | () => { |
| 423 | postJobResultMessage(jobUID, true); |
| 424 | activeSubscriptions.delete(jobUID); |
| 425 | }, |
| 426 | ); |
| 427 | activeSubscriptions.set(jobUID, subscription); |
| 428 | } else { |
| 429 | try { |
| 430 | const result = yield syncResult; |
| 431 | postJobResultMessage(jobUID, true, common_1.serialize(result)); |
| 432 | } catch (error) { |
| 433 | postJobErrorMessage(jobUID, common_1.serialize(error)); |
| 434 | } |
| 435 | } |
| 436 | }); |
| 437 | } |
| 438 | function expose2(exposed) { |
| 439 | if (!implementation_1.default.isWorkerRuntime()) { |
| 440 | throw Error('expose() called in the master thread.'); |
no test coverage detected