Hyperlinkv0.8.0-beta.28

FiberSet

FiberSet.makeconsteffect/FiberSet.ts:144
<A = unknown, E = unknown>(): Effect.Effect<
  FiberSet<A, E>,
  never,
  Scope.Scope
>

Creates a scoped FiberSet for storing fibers.

Details

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.

Example (Creating a scoped FiberSet)

import { Effect, FiberSet } from "effect"

Effect.gen(function*() {
  const set = yield* FiberSet.make()

  // run some effects and add the fibers to the set
  yield* FiberSet.run(set, Effect.never)
  yield* FiberSet.run(set, Effect.never)

  yield* Effect.sleep(1000)
}).pipe(
  Effect.scoped // The fibers will be interrupted when the scope is closed
)
constructors
Source effect/FiberSet.ts:14414 lines
export const make = <A = unknown, E = unknown>(): Effect.Effect<FiberSet<A, E>, never, Scope.Scope> =>
  Effect.acquireRelease(
    Effect.sync(() => makeUnsafe(new Set(), Deferred.makeUnsafe())),
    (set) =>
      Effect.suspend(() => {
        const state = set.state
        if (state._tag === "Closed") return Effect.void
        set.state = { _tag: "Closed" }
        const fibers = state.backing
        return Fiber.interruptAll(fibers).pipe(
          Deferred.into(set.deferred)
        )
      })
  )
Referenced by 2 symbols