<K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>Removes all fibers from the FiberMap, interrupting them.
Example (Clearing all fibers)
import { Effect, FiberMap } from "effect"
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)
yield* FiberMap.run(map, "task3", Effect.never)
console.log(yield* FiberMap.size(map)) // 3
// Clear all fibers (this will interrupt all of them)
yield* FiberMap.clear(map)
console.log(yield* FiberMap.size(map)) // 0
})combinators
Source effect/FiberMap.ts:6887 lines
export const const clear: <K, A, E>(
self: FiberMap<K, A, E>
) => Effect.Effect<void>
Removes all fibers from the FiberMap, interrupting them.
Example (Clearing all fibers)
import { Effect, FiberMap } from "effect"
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)
yield* FiberMap.run(map, "task3", Effect.never)
console.log(yield* FiberMap.size(map)) // 3
// Clear all fibers (this will interrupt all of them)
yield* FiberMap.clear(map)
console.log(yield* FiberMap.size(map)) // 0
})
clear = <function (type parameter) K in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>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>K, function (type parameter) A in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>A, function (type parameter) E in <K, A, E>(self: FiberMap<K, A, E>): Effect.Effect<void>E>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void> =>
import EffectEffect.suspend(() => {
if (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 === "Closed") {
return import EffectEffect.void
}
return import FiberFiber.interruptAllAs(import MutableHashMapMutableHashMap.const values: <K, V>(
self: MutableHashMap<K, V>
) => Iterable<V>
Returns an iterable over the values in the MutableHashMap.
When to use
Use to iterate over the values currently stored in a mutable hash map.
Example (Reading values)
import { MutableHashMap } from "effect"
const map = MutableHashMap.make(
["apple", 1],
["banana", 2],
["cherry", 3]
)
const allValues = Array.from(MutableHashMap.values(map))
console.log(allValues) // [1, 2, 3]
// Useful for calculations
const total = allValues.reduce((sum, value) => sum + value, 0)
console.log(total) // 6
// Filter values
const largeValues = allValues.filter((value) => value > 1)
console.log(largeValues) // [2, 3]
values(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), const internalFiberId: -1internalFiberId)
})