(
options: {
readonly try: (signal: AbortSignal) => PromiseLike<A>
readonly catch: (error: unknown) => E
} | ((signal: AbortSignal) => PromiseLike<A>)
)
| 1224 | |
| 1225 | /** @internal */ |
| 1226 | export const tryPromise = <A, E = Cause.UnknownError>( |
| 1227 | options: { |
| 1228 | readonly try: (signal: AbortSignal) => PromiseLike<A> |
| 1229 | readonly catch: (error: unknown) => E |
| 1230 | } | ((signal: AbortSignal) => PromiseLike<A>) |
| 1231 | ): Effect.Effect<A, E> => { |
| 1232 | const f = typeof options === "function" ? options : options.try |
| 1233 | const catcher = typeof options === "function" |
| 1234 | ? ((cause: unknown) => new UnknownError(cause, "An error occurred in Effect.tryPromise")) |
| 1235 | : options.catch |
| 1236 | return callbackOptions<A, E>(function(resume, signal) { |
| 1237 | // Defer the catcher until the fiber restores its async context. |
| 1238 | const failWithCatch = (cause: unknown) => |
| 1239 | suspend(() => { |
| 1240 | try { |
| 1241 | return fail(internalCall(() => catcher(cause)) as E) |
| 1242 | } catch (err) { |
| 1243 | return die(err) |
| 1244 | } |
| 1245 | }) |
| 1246 | try { |
| 1247 | f(signal!).then( |
| 1248 | (a) => resume(succeed(a)), |
| 1249 | (e) => resume(failWithCatch(e)) |
| 1250 | ) |
| 1251 | } catch (err) { |
| 1252 | resume(failWithCatch(err)) |
| 1253 | } |
| 1254 | }, f.length !== 0) |
| 1255 | } |
| 1256 | |
| 1257 | /** @internal */ |
| 1258 | export const withFiberId = <A, E, R>( |
nothing calls this directly
no test coverage detected