MCPcopy Create free account
hub / github.com/effect-app/libs / runtimePromise

Function runtimePromise

repos/effect/packages/effect/src/FiberHandle.ts:714–753  ·  view source on GitHub ↗
(self: FiberHandle<A, E>)

Source from the content-addressed store, hash-verified

712 )
713
714/**
715 * Captures the current runtime and returns a function for running effects in
716 * an existing `FiberHandle` as Promises.
717 *
718 * **Details**
719 *
720 * Each call stores the forked fiber in the handle and interrupts the previous
721 * fiber unless `onlyIfMissing` is set. The Promise resolves with the effect's
722 * success value or rejects with the squashed failure cause.
723 *
724 * **Example** (Capturing a runtime for promises)
725 *
726 * ```ts import.meta.vitest
727 * import { Effect, FiberHandle } from "effect"
728 *
729 * const program = Effect.gen(function*() {
730 * const handle = yield* FiberHandle.make()
731 * const runPromise = yield* FiberHandle.runtimePromise(handle)<never>()
732 *
733 * // Run an effect and get a promise
734 * const promise = runPromise(Effect.succeed("hello"))
735 * return yield* Effect.promise(() => promise)
736 * })
737 *
738 * const actual = await Effect.runPromise(Effect.scoped(program))
739 * actual // => "hello"
740 * ```
741 *
742 * @category combinators
743 * @since 3.13.0
744 */
745export const runtimePromise = <A, E>(self: FiberHandle<A, E>): <R = never>() => Effect.Effect<
746 <XE extends E, XA extends A>(
747 effect: Effect.Effect<XA, XE, R>,
748 options?:
749 | {
750 readonly signal?: AbortSignal | undefined
751 readonly scheduler?: Scheduler | undefined
752 readonly onlyIfMissing?: boolean | undefined
753 readonly propagateInterruption?: boolean | undefined
754 }
755 | undefined
756 ) => Promise<XA>,

Callers 1

makeRuntimePromiseFunction · 0.70

Calls 5

runForkFunction · 0.85
addObserverMethod · 0.80
runtimeFunction · 0.70
resolveFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…