MCPcopy Create free account
hub / github.com/Effect-TS/effect / tryPromise

Function tryPromise

packages/effect/src/internal/effect.ts:1061–1088  ·  view source on GitHub ↗
(
  options: {
    readonly try: (signal: AbortSignal) => PromiseLike<A>
    readonly catch: (error: unknown) => E
  } | ((signal: AbortSignal) => PromiseLike<A>)
)

Source from the content-addressed store, hash-verified

1059
1060/** @internal */
1061export 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 */
1091export const withFiberId = <A, E, R>(

Callers

nothing calls this directly

Calls 4

failWithCatchFunction · 0.85
succeedFunction · 0.70
fFunction · 0.50
resumeFunction · 0.50

Tested by

no test coverage detected