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

Function tryPromise

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

Source from the content-addressed store, hash-verified

1088 * @category constructors
1089 */
1090export const tryPromise = <A, E>(options: {
1091 readonly try: (signal: AbortSignal) => PromiseLike<A>
1092 readonly catch: (error: unknown) => E
1093}): Micro<A, E> =>
1094 asyncOptions<A, E>(function(resume, signal) {
1095 try {
1096 options.try(signal!).then(
1097 (a) => resume(succeed(a)),
1098 (e) => resume(fail(options.catch(e)))
1099 )
1100 } catch (err) {
1101 resume(fail(options.catch(err)))
1102 }
1103 }, options.try.length !== 0)
1104
1105/**
1106 * Create a `Micro` effect using the current `MicroFiber`.

Callers 1

core-effect.tsFile · 0.85

Calls 3

resumeFunction · 0.70
failFunction · 0.70
succeedFunction · 0.50

Tested by

no test coverage detected