Skip to content

FiberSet

16 exports Added in v2.0.0 Source

Other

add

Added in v2.0.0 Source

Add a fiber to the FiberSet. When the fiber completes, it will be removed.

Signature

declare const add: {
  <A, E, XE, XA>(
    fiber: RuntimeFiber<XA, XE>,
    options?: {
      readonly propagateInterruption?: boolean;
    },
  ): (self: FiberSet<A, E>) => Effect<void>;
  <A, E, XE, XA>(
    self: FiberSet<A, E>,
    fiber: RuntimeFiber<XA, XE>,
    options?: {
      readonly propagateInterruption?: boolean;
    },
  ): Effect<void>;
};

awaitEmpty

Added in v3.13.0 Source

Wait until the fiber set is empty.

Signature

declare function awaitEmpty<A, E>(self: FiberSet<A, E>): Effect<void>;

clear

Added in v2.0.0 Source

Signature

declare function clear<A, E>(self: FiberSet<A, E>): Effect<void>;

FiberSet interface

Added in v2.0.0 Source

Signature

interface FiberSet<out A = unknown, out E = unknown> extends Pipeable, Inspectable, "/home/runner/work/website/website/.effect-source-v3/packages/effect/src/Iterable"<Fiber.RuntimeFiber<A, E>> {
  readonly [TypeId]: typeof TypeId;
  readonly deferred: Deferred<void, unknown>;
}

isFiberSet

Added in v2.0.0 Source

Signature

declare function isFiberSet(u: unknown): u is FiberSet<unknown, unknown>;

join

Added in v2.0.0 Source

Join all fibers in the FiberSet. If any of the Fiber's in the set terminate with a failure, the returned Effect will terminate with the first failure that occurred.

Signature

declare function join<A, E>(self: FiberSet<A, E>): Effect<void, E>;

make

Added in v2.0.0 Source

A FiberSet can be used to store a collection of fibers. When the associated Scope is closed, all fibers in the set will be interrupted.

You can add fibers to the set using FiberSet.add or FiberSet.run, and the fibers will be automatically removed from the FiberSet when they complete.

Signature

declare function make<A = unknown, E = unknown>(): Effect<FiberSet<A, E>, never, Scope>;

makeRuntime

Added in v2.0.0 Source

Create an Effect run function that is backed by a FiberSet.

Signature

declare function makeRuntime<R = never, A = unknown, E = unknown>(): Effect<
  <XE, XA>(effect: Effect<XA, XE, R>, options?: RunForkOptions) => RuntimeFiber<XA, XE>,
  never,
  Scope | R
>;

Create an Effect run function that is backed by a FiberSet.

Signature

declare function makeRuntimePromise<R = never, A = unknown, E = unknown>(): Effect<
  <XE, XA>(effect: Effect<XA, XE, R>, options?: RunForkOptions) => Promise<XA>,
  never,
  Scope | R
>;

run

Added in v2.0.0 Source

Fork an Effect and add the forked fiber to the FiberSet. When the fiber completes, it will be removed from the FiberSet.

Signature

declare const run: {
  <A, E>(
    self: FiberSet<A, E>,
    options?: {
      readonly propagateInterruption?: boolean;
    },
  ): <R, XE, XA>(effect: Effect<XA, XE, R>) => Effect<RuntimeFiber<XA, XE>, never, R>;
  <A, E, R, XE, XA>(
    self: FiberSet<A, E>,
    effect: Effect<XA, XE, R>,
    options?: {
      readonly propagateInterruption?: boolean;
    },
  ): Effect<RuntimeFiber<XA, XE>, never, R>;
};

runtime

Added in v2.0.0 Source

Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberSet.

Signature

declare const runtime: <A, E>(
  self: FiberSet<A, E>,
) => <R = never>() => Effect.Effect<
  <XE extends E, XA extends A>(
    effect: Effect.Effect<XA, XE, R>,
    options?: Runtime.RunForkOptions & {
      readonly propagateInterruption?: boolean;
    },
  ) => Fiber.RuntimeFiber<XA, XE>,
  never,
  R
>;

Example

import { Context, Effect, FiberSet } from "effect"

interface Users {
  readonly _: unique symbol
}
const Users = Context.GenericTag<
  Users,
  {
    getAll: Effect.Effect<Array<unknown>>
  }
>("Users")

Effect.gen(function* () {
  const set = yield* FiberSet.make()
  const run = yield* FiberSet.runtime(set)<Users>()

  // run some effects and add the fibers to the set
  run(Effect.andThen(Users, (_) => _.getAll))
}).pipe(
  Effect.scoped, // The fibers will be interrupted when the scope is closed
)

runtimePromise

Added in v3.13.0 Source

Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberSet.

The returned run function will return Promise's.

Signature

declare function runtimePromise<A, E>(
  self: FiberSet<A, E>,
): <R = never>() => Effect<
  <XE, XA>(
    effect: Effect<XA, XE, R>,
    options?: RunForkOptions & {
      readonly propagateInterruption?: boolean;
    },
  ) => Promise<XA>,
  never,
  R
>;

size

Added in v2.0.0 Source

Signature

declare function size<A, E>(self: FiberSet<A, E>): Effect<number>;

TypeId

Added in v2.0.0 Source

Signature

declare const TypeId: unique symbol;

TypeId type

Added in v2.0.0 Source

Signature

type TypeId = typeof TypeId;

unsafeAdd

Added in v2.0.0 Source

Add a fiber to the FiberSet. When the fiber completes, it will be removed.

Signature

declare const unsafeAdd: {
  <A, E, XE, XA>(
    fiber: RuntimeFiber<XA, XE>,
    options?: {
      readonly interruptAs?: FiberId.FiberId;
      readonly propagateInterruption?: boolean;
    },
  ): (self: FiberSet<A, E>) => void;
  <A, E, XE, XA>(
    self: FiberSet<A, E>,
    fiber: RuntimeFiber<XA, XE>,
    options?: {
      readonly interruptAs?: FiberId.FiberId;
      readonly propagateInterruption?: boolean;
    },
  ): void;
};