(
options: {
readonly try: (signal: AbortSignal) => PromiseLike<A>
readonly catch: (error: unknown) => E
} | ((signal: AbortSignal) => PromiseLike<A>)
)
| 1059 | |
| 1060 | /** @internal */ |
| 1061 | export const tryPromise = <A, E = Cause.UnknownError>( |
| 1062 | options: { |
| 1063 | readonly try: (signal: AbortSignal) => PromiseLike<A> |
| 1064 | readonly catch: (error: unknown) => E |
| 1065 | } | ((signal: AbortSignal) => PromiseLike<A>) |
| 1066 | ): Effect.Effect<A, E> => { |
| 1067 | const f = typeof options === "function" ? options : options.try |
| 1068 | const catcher = typeof options === "function" |
| 1069 | ? ((cause: unknown) => new UnknownError(cause, "An error occurred in Effect.tryPromise")) |
| 1070 | : options.catch |
| 1071 | return callbackOptions<A, E>(function(resume, signal) { |
| 1072 | const failWithCatch = (cause: unknown) => { |
| 1073 | try { |
| 1074 | resume(fail(internalCall(() => catcher(cause)) as E)) |
| 1075 | } catch (err) { |
| 1076 | resume(die(err)) |
| 1077 | } |
| 1078 | } |
| 1079 | try { |
| 1080 | internalCall(() => f(signal!)).then( |
| 1081 | (a) => resume(succeed(a)), |
| 1082 | failWithCatch |
| 1083 | ) |
| 1084 | } catch (err) { |
| 1085 | failWithCatch(err) |
| 1086 | } |
| 1087 | }, f.length !== 0) |
| 1088 | } |
| 1089 | |
| 1090 | /** @internal */ |
| 1091 | export const withFiberId = <A, E, R>( |
nothing calls this directly
no test coverage detected