Package: effect
Module: FiberMap
A FiberMap is a collection of fibers, indexed by a key. When the associated Scope is closed, all fibers in the map will be interrupted. Fibers are automatically removed from the map when they complete.
Example (Managing fibers in a map)
import { Effect, FiberMap } from "effect"
// Create a FiberMap with string keys
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// Add some fibers to the map
yield* FiberMap.run(map, "task1", Effect.never)
yield* FiberMap.run(map, "task2", Effect.never)
// Get the size of the map
const size = yield* FiberMap.size(map)
console.log(size) // 2
})
Signature
export interface FiberMap<in out K, out A = unknown, out E = unknown>
extends Pipeable, Inspectable.Inspectable, Iterable<[K, Fiber.Fiber<A, E>]>
{
readonly [TypeId]: typeof TypeId
readonly deferred: Deferred.Deferred<void, unknown>
state: {
readonly _tag: "Open"
readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>>
} | {
readonly _tag: "Closed"
}
}
Since v2.0.0