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

Function runtimePromise

packages/effect/src/FiberMap.ts:987–1021  ·  view source on GitHub ↗
(self: FiberMap<K, A, E>)

Source from the content-addressed store, hash-verified

985 * @since 3.13.0
986 */
987export const runtimePromise = <K, A, E>(self: FiberMap<K, A, E>): <R = never>() => Effect.Effect<
988 <XE extends E, XA extends A>(
989 key: K,
990 effect: Effect.Effect<XA, XE, R>,
991 options?:
992 | Effect.RunOptions & {
993 readonly onlyIfMissing?: boolean | undefined
994 readonly propagateInterruption?: boolean | undefined
995 }
996 | undefined
997 ) => Promise<XA>,
998 never,
999 R
1000> =>
1001<R>() =>
1002 Effect.map(
1003 runtime(self)<R>(),
1004 (runFork) =>
1005 <XE extends E, XA extends A>(
1006 key: K,
1007 effect: Effect.Effect<XA, XE, R>,
1008 options?:
1009 | Effect.RunOptions & { readonly propagateInterruption?: boolean | undefined }
1010 | undefined
1011 ): Promise<XA> =>
1012 new Promise((resolve, reject) =>
1013 runFork(key, effect, options).addObserver((exit) => {
1014 if (Exit.isSuccess(exit)) {
1015 resolve(exit.value)
1016 } else {
1017 reject(Cause.squash(exit.cause))
1018 }
1019 })
1020 )
1021 )
1022
1023/**
1024 * Gets the number of fibers currently in the FiberMap.

Callers 1

makeRuntimePromiseFunction · 0.70

Calls 6

runForkFunction · 0.85
addObserverMethod · 0.80
runtimeFunction · 0.70
resolveFunction · 0.70
rejectFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected