Hyperlinkv0.8.0-beta.28

FiberMap

FiberMap.getconsteffect/FiberMap.ts:534
<K>(key: K): <A, E>(
  self: FiberMap<K, A, E>
) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>
<K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<
  Option.Option<Fiber.Fiber<A, E>>
>

Retrieves a fiber from the FiberMap effectfully.

Details

Returns an Option wrapped in Effect.

Example (Retrieving a fiber)

import { Deferred, Effect, Fiber, FiberMap } from "effect"

const program = Effect.gen(function*() {
  const map = yield* FiberMap.make<string>()
  const deferred = yield* Deferred.make<string>()

  // Add a fiber to the map
  const fiber = yield* Effect.forkChild(Deferred.await(deferred))
  yield* FiberMap.set(map, "greeting", fiber)

  // Retrieve the fiber with error handling
  const retrieved = yield* FiberMap.get(map, "greeting")
  if (retrieved._tag === "Some") {
    yield* Deferred.succeed(deferred, "Hello")

    const result = yield* Fiber.join(retrieved.value)
    console.log(result) // "Hello"
  }
})
combinators
export const get: {
  <K>(key: K): <A, E>(self: FiberMap<K, A, E>) => Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>
  <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>>
} = dual(
  2,
  <K, A, E>(self: FiberMap<K, A, E>, key: K): Effect.Effect<Option.Option<Fiber.Fiber<A, E>>> =>
    Effect.suspend(() => Effect.succeed(getUnsafe(self, key)))
)