<A, E>(self: FiberSet<A, E>): Effect.Effect<number>Gets the number of fibers currently in the FiberSet.
Example (Checking the set size)
import { Effect, FiberSet } from "effect"
const program = Effect.gen(function*() {
const set = yield* FiberSet.make()
console.log(yield* FiberSet.size(set)) // 0
// Add some fibers
yield* FiberSet.run(set, Effect.never)
yield* FiberSet.run(set, Effect.never)
console.log(yield* FiberSet.size(set)) // 2
})export const const size: <A, E>(
self: FiberSet<A, E>
) => Effect.Effect<number>
Gets the number of fibers currently in the FiberSet.
Example (Checking the set size)
import { Effect, FiberSet } from "effect"
const program = Effect.gen(function*() {
const set = yield* FiberSet.make()
console.log(yield* FiberSet.size(set)) // 0
// Add some fibers
yield* FiberSet.run(set, Effect.never)
yield* FiberSet.run(set, Effect.never)
console.log(yield* FiberSet.size(set)) // 2
})
size = <function (type parameter) A in <A, E>(self: FiberSet<A, E>): Effect.Effect<number>A, function (type parameter) E in <A, E>(self: FiberSet<A, E>): Effect.Effect<number>E>(self: FiberSet<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: Set<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 FiberSet<out A = unknown, out E = unknown>A FiberSet is a collection of fibers that can be managed together.
When the associated Scope is closed, all fibers in the set will be interrupted.
Example (Managing fibers in a set)
import { Effect, FiberSet } from "effect"
const program = Effect.gen(function*() {
const set = yield* FiberSet.make<string, string>()
// Add fibers to the set
yield* FiberSet.run(set, Effect.succeed("hello"))
yield* FiberSet.run(set, Effect.succeed("world"))
// Wait for all fibers to complete
yield* FiberSet.awaitEmpty(set)
})
FiberSet<function (type parameter) A in <A, E>(self: FiberSet<A, E>): Effect.Effect<number>A, function (type parameter) E in <A, E>(self: FiberSet<A, E>): Effect.Effect<number>E>): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<number> =>
import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => self: FiberSet<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: Set<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.FiberSet<A, E>.state: { readonly _tag: "Open"; readonly backing: Set<Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" }state._tag: "Open" | "Closed"_tag === "Closed" ? 0 : self: FiberSet<A, E>(parameter) self: {
deferred: Deferred.Deferred<void, unknown>;
state: { readonly _tag: "Open"; readonly backing: Set<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.FiberSet<A, E>.state: { readonly _tag: "Open"; readonly backing: Set<Fiber.Fiber<A, E>> } | { readonly _tag: "Closed" }state.backing: Set<Fiber.Fiber<A, E>>backing.Set<T>.size: numbersize)