Skip to content

ManagedRuntime

8 exports Added in v2.0.0 Source

Guards

Checks if the provided argument is a ManagedRuntime.

Signature

declare const isManagedRuntime: (input: unknown) => input is ManagedRuntime<unknown, unknown>;

Models

ManagedRuntime interface

Added in v2.0.0 Source

Signature

interface ManagedRuntime<in R, out ER> extends Effect<Runtime.Runtime<R>, ER> {
  readonly [ignoreSymbol]?: ManagedRuntimeUnifyIgnore;
  readonly [TypeId]: typeof TypeId;
  readonly [typeSymbol]?: unknown;
  readonly [unifySymbol]?: ManagedRuntimeUnify<ManagedRuntime<R, ER>>;
  readonly dispose: () => Promise<void>;
  readonly disposeEffect: Effect<void, never, never>;
  readonly memoMap: MemoMap;
  readonly runCallback: <A, E>(
    effect: Effect<A, E, R>,
    options?: RunCallbackOptions<A, ER | E>,
  ) => Cancel<A, ER | E>;
  readonly runFork: <A, E>(
    self: Effect<A, E, R>,
    options?: RunForkOptions,
  ) => RuntimeFiber<A, ER | E>;
  readonly runPromise: <A, E>(
    effect: Effect<A, E, R>,
    options?: {
      readonly signal?: AbortSignal;
    },
  ) => Promise<A>;
  readonly runPromiseExit: <A, E>(
    effect: Effect<A, E, R>,
    options?: {
      readonly signal?: AbortSignal;
    },
  ) => Promise<Exit<A, ER | E>>;
  readonly runSync: <A, E>(effect: Effect<A, E, R>) => A;
  readonly runSyncExit: <A, E>(effect: Effect<A, E, R>) => Exit<A, ER | E>;
  readonly runtime: () => Promise<Runtime<R>>;
  readonly runtimeEffect: Effect<Runtime<R>, ER>;
}

ManagedRuntimeUnify interface

Added in v3.9.0 Source

Signature

interface ManagedRuntimeUnify<
  A extends {
    [typeSymbol]?: any;
  },
> extends EffectUnify<A> {
  ManagedRuntime?: () => Extract<A[typeof typeSymbol], ManagedRuntime<any, any>>;
}

ManagedRuntimeUnifyIgnore interface

Added in v3.9.0 Source

Signature

interface ManagedRuntimeUnifyIgnore extends EffectUnifyIgnore {
  Effect?: true;
}

Other

Runtime Class

make

Added in v2.0.0 Source

Convert a Layer into an ManagedRuntime, that can be used to run Effect's using your services.

Signature

declare const make: <R, E>(
  layer: Layer.Layer<R, E, never>,
  memoMap?: Layer.MemoMap,
) => ManagedRuntime<R, E>;

Example

import { Console, Effect, Layer, ManagedRuntime } from "effect"

class Notifications extends Effect.Tag("Notifications")<
  Notifications,
  { readonly notify: (message: string) => Effect.Effect<void> }
>() {
  static Live = Layer.succeed(this, { notify: (message) => Console.log(message) })
}

async function main() {
  const runtime = ManagedRuntime.make(Notifications.Live)
  await runtime.runPromise(Notifications.notify("Hello, world!"))
  await runtime.dispose()
}

main()

Symbol

TypeId

Added in v3.9.0 Source

Signature

declare const TypeId: unique symbol;

TypeId type

Added in v3.9.0 Source

Signature

type TypeId = typeof TypeId;