<K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>Waits for the FiberMap to be empty. This will wait for all currently running fibers to complete.
Example (Waiting for an empty map)
import { Effect, FiberMap } from "effect"
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// Add some fibers that will complete after a delay
yield* FiberMap.run(map, "task1", Effect.sleep(1000))
yield* FiberMap.run(map, "task2", Effect.sleep(2000))
console.log("Waiting for all fibers to complete...")
// Wait for the map to be empty
yield* FiberMap.awaitEmpty(map)
console.log("All fibers completed!")
console.log(yield* FiberMap.size(map)) // 0
})export const const awaitEmpty: <K, A, E>(
self: FiberMap<K, A, E>
) => Effect.Effect<void, E>
Waits for the FiberMap to be empty.
This will wait for all currently running fibers to complete.
Example (Waiting for an empty map)
import { Effect, FiberMap } from "effect"
const program = Effect.gen(function*() {
const map = yield* FiberMap.make<string>()
// Add some fibers that will complete after a delay
yield* FiberMap.run(map, "task1", Effect.sleep(1000))
yield* FiberMap.run(map, "task2", Effect.sleep(2000))
console.log("Waiting for all fibers to complete...")
// Wait for the map to be empty
yield* FiberMap.awaitEmpty(map)
console.log("All fibers completed!")
console.log(yield* FiberMap.size(map)) // 0
})
awaitEmpty = <function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>E>(self: FiberMap<K, A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface FiberMap<in out K, out A = unknown, out E = unknown>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
})
FiberMap<function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>E>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void, E>E> =>
import EffectEffect.whileLoop({
while: () => booleanwhile: () => self: FiberMap<K, A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.FiberMap<K, A, E>.state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" }state._tag: "Open" | "Closed"_tag === "Open" && import MutableHashMapMutableHashMap.const size: <K, V>(
self: MutableHashMap<K, V>
) => number
Returns the number of key-value pairs in the MutableHashMap.
When to use
Use to read how many entries are currently stored in the mutable hash map.
Example (Checking map size)
import { MutableHashMap } from "effect"
const map = MutableHashMap.empty<string, number>()
console.log(MutableHashMap.size(map)) // 0
MutableHashMap.set(map, "key1", 42)
MutableHashMap.set(map, "key2", 100)
console.log(MutableHashMap.size(map)) // 2
MutableHashMap.remove(map, "key1")
console.log(MutableHashMap.size(map)) // 1
MutableHashMap.clear(map)
console.log(MutableHashMap.size(map)) // 0
size(self: FiberMap<K, A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.FiberMap<K, A, E>.state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" }state.backing: MutableHashMap.MutableHashMap<
K,
Fiber.Fiber<A, E>
>
(property) backing: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
backing) > 0,
body: () => anybody: () => import FiberFiber.await(import IterableIterable.const headUnsafe: <[K, Fiber.Fiber<A, E>]>(self: Iterable<[K, Fiber.Fiber<A, E>]>) => [K, Fiber.Fiber<A, E>]Gets the first element of an Iterable without returning an Option.
When to use
Use when the Iterable is known to be non-empty and direct access to the
first element is preferred over handling Option.none.
Gotchas
Throws if the Iterable is empty.
Example (Getting the first element unsafely)
import { Iterable } from "effect"
const numbers = [1, 2, 3]
console.log(Iterable.headUnsafe(numbers)) // 1
const letters = "hello"
console.log(Iterable.headUnsafe(letters)) // "h"
// Iterable.headUnsafe(Iterable.empty<number>())
// throws Error: "headUnsafe: empty iterable"
// Use only when you're certain the iterable is non-empty
const nonEmpty = Iterable.range(1, 10)
console.log(Iterable.headUnsafe(nonEmpty)) // 1
headUnsafe(self: FiberMap<K, A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: MutableHashMap.MutableHashMap<K, Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" };
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self)[1]),
step: LazyArg<void>step: const constVoid: LazyArg<void>Returns no meaningful value when called.
When to use
Use when you need a thunk that is called only for its effect and has no
meaningful return value.
Example (Returning void from a thunk)
import { Function } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(Function.constVoid(), undefined)
constVoid
})