| 14698 | } |
| 14699 | |
| 14700 | function fnApply(options: { |
| 14701 | readonly self: any |
| 14702 | readonly body: Function |
| 14703 | readonly args: Array<any> |
| 14704 | readonly pipeables: Array<any> |
| 14705 | readonly spanName: string |
| 14706 | readonly spanOptions: Tracer.SpanOptions |
| 14707 | readonly errorDef: Error |
| 14708 | readonly errorCall: Error |
| 14709 | }) { |
| 14710 | let effect: Effect<any, any, any> |
| 14711 | let fnError: any = undefined |
| 14712 | if (isGeneratorFunction(options.body)) { |
| 14713 | effect = core.fromIterator(() => options.body.apply(options.self, options.args)) |
| 14714 | } else { |
| 14715 | try { |
| 14716 | const result = options.body.apply(options.self, options.args) |
| 14717 | if (core.isEffect(result)) { |
| 14718 | effect = result |
| 14719 | } else { |
| 14720 | // transpiled generator bodies return an iterator; reuse it for the first run |
| 14721 | let first = true |
| 14722 | effect = core.fromIterator(() => { |
| 14723 | if (first) { |
| 14724 | first = false |
| 14725 | return result |
| 14726 | } |
| 14727 | return options.body.apply(options.self, options.args) |
| 14728 | }) |
| 14729 | } |
| 14730 | } catch (error) { |
| 14731 | fnError = error |
| 14732 | effect = die(error) |
| 14733 | } |
| 14734 | } |
| 14735 | if (options.pipeables.length > 0) { |
| 14736 | try { |
| 14737 | for (const x of options.pipeables) { |
| 14738 | effect = x(effect, ...options.args) |
| 14739 | } |
| 14740 | } catch (error) { |
| 14741 | effect = fnError |
| 14742 | ? failCause(internalCause.sequential( |
| 14743 | internalCause.die(fnError), |
| 14744 | internalCause.die(error) |
| 14745 | )) |
| 14746 | : die(error) |
| 14747 | } |
| 14748 | } |
| 14749 | |
| 14750 | let cache: false | string = false |
| 14751 | const captureStackTrace = () => { |
| 14752 | if (cache !== false) { |
| 14753 | return cache |
| 14754 | } |
| 14755 | if (options.errorCall.stack) { |
| 14756 | const stackDef = options.errorDef.stack!.trim().split("\n") |
| 14757 | const stackCall = options.errorCall.stack.trim().split("\n") |