FiberSet.ts overview
Since v2.0.0
Exports Grouped by Category
utils
FiberSet (interface)
Signature
export interface FiberSet<out A = unknown, out E = unknown>
extends Pipeable,
Inspectable.Inspectable,
Iterable<Fiber.RuntimeFiber<A, E>> {
readonly [TypeId]: TypeId
readonly deferred: Deferred.Deferred<void, unknown>
/** @internal */
state:
| {
readonly _tag: "Open"
readonly backing: Set<Fiber.RuntimeFiber<A, E>>
}
| {
readonly _tag: "Closed"
}
}
Since v2.0.0
TypeId
Signature
declare const TypeId: unique symbol
Since v2.0.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v2.0.0
add
Add a fiber to the FiberSet. When the fiber completes, it will be removed.
Signature
declare const add: {
<A, E, XE extends E, XA extends A>(
fiber: Fiber.RuntimeFiber<XA, XE>,
options?: { readonly propagateInterruption?: boolean | undefined } | undefined
): (self: FiberSet<A, E>) => Effect.Effect<void>
<A, E, XE extends E, XA extends A>(
self: FiberSet<A, E>,
fiber: Fiber.RuntimeFiber<XA, XE>,
options?: { readonly propagateInterruption?: boolean | undefined } | undefined
): Effect.Effect<void>
}
Since v2.0.0
awaitEmpty
Wait until the fiber set is empty.
Signature
declare const awaitEmpty: <A, E>(self: FiberSet<A, E>) => Effect.Effect<void>
Since v3.13.0
clear
Signature
declare const clear: <A, E>(self: FiberSet<A, E>) => Effect.Effect<void>
Since v2.0.0
isFiberSet
Signature
declare const isFiberSet: (u: unknown) => u is FiberSet<unknown, unknown>
Since v2.0.0
join
Join all fibers in the FiberSet. If any of the Fiber’s in the set terminate with a failure, the returned Effect will terminate with the first failure that occurred.
Example
import { Effect, FiberSet } from "effect"
Effect.gen(function* (_) {
const set = yield* _(FiberSet.make())
yield* _(FiberSet.add(set, Effect.runFork(Effect.fail("error"))))
// parent fiber will fail with "error"
yield* _(FiberSet.join(set))
})
Signature
declare const join: <A, E>(self: FiberSet<A, E>) => Effect.Effect<void, E>
Since v2.0.0
make
A FiberSet can be used to store a collection of fibers. When the associated Scope is closed, all fibers in the set will be interrupted.
You can add fibers to the set using FiberSet.add or FiberSet.run, and the fibers will be automatically removed from the FiberSet when they complete.
Example
import { Effect, FiberSet } from "effect"
Effect.gen(function* () {
const set = yield* FiberSet.make()
// run some effects and add the fibers to the set
yield* FiberSet.run(set, Effect.never)
yield* FiberSet.run(set, Effect.never)
yield* Effect.sleep(1000)
}).pipe(
Effect.scoped // The fibers will be interrupted when the scope is closed
)
Signature
declare const make: <A = unknown, E = unknown>() => Effect.Effect<FiberSet<A, E>, never, Scope.Scope>
Since v2.0.0
makeRuntime
Create an Effect run function that is backed by a FiberSet.
Signature
declare const makeRuntime: <R = never, A = unknown, E = unknown>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?: Runtime.RunForkOptions | undefined
) => Fiber.RuntimeFiber<XA, XE>,
never,
Scope.Scope | R
>
Since v2.0.0
makeRuntimePromise
Create an Effect run function that is backed by a FiberSet.
Signature
declare const makeRuntimePromise: <R = never, A = unknown, E = unknown>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?: Runtime.RunForkOptions | undefined
) => Promise<XA>,
never,
Scope.Scope | R
>
Since v3.13.0
run
Fork an Effect and add the forked fiber to the FiberSet. When the fiber completes, it will be removed from the FiberSet.
Signature
declare const run: {
<A, E>(
self: FiberSet<A, E>,
options?: { readonly propagateInterruption?: boolean | undefined } | undefined
): <R, XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>
) => Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
<A, E, R, XE extends E, XA extends A>(
self: FiberSet<A, E>,
effect: Effect.Effect<XA, XE, R>,
options?: { readonly propagateInterruption?: boolean | undefined } | undefined
): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R>
}
Since v2.0.0
runtime
Capture a Runtime and use it to fork Effect’s, adding the forked fibers to the FiberSet.
Example
import { Context, Effect, FiberSet } from "effect"
interface Users {
readonly _: unique symbol
}
const Users = Context.GenericTag<
Users,
{
getAll: Effect.Effect<Array<unknown>>
}
>("Users")
Effect.gen(function* () {
const set = yield* FiberSet.make()
const run = yield* FiberSet.runtime(set)<Users>()
// run some effects and add the fibers to the set
run(Effect.andThen(Users, (_) => _.getAll))
}).pipe(
Effect.scoped // The fibers will be interrupted when the scope is closed
)
Signature
declare const runtime: <A, E>(
self: FiberSet<A, E>
) => <R = never>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?: (Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }) | undefined
) => Fiber.RuntimeFiber<XA, XE>,
never,
R
>
Since v2.0.0
runtimePromise
Capture a Runtime and use it to fork Effect’s, adding the forked fibers to the FiberSet.
The returned run function will return Promise’s.
Signature
declare const runtimePromise: <A, E>(
self: FiberSet<A, E>
) => <R = never>() => Effect.Effect<
<XE extends E, XA extends A>(
effect: Effect.Effect<XA, XE, R>,
options?: (Runtime.RunForkOptions & { readonly propagateInterruption?: boolean | undefined }) | undefined
) => Promise<XA>,
never,
R
>
Since v3.13.0
size
Signature
declare const size: <A, E>(self: FiberSet<A, E>) => Effect.Effect<number>
Since v2.0.0
unsafeAdd
Add a fiber to the FiberSet. When the fiber completes, it will be removed.
Signature
declare const unsafeAdd: {
<A, E, XE extends E, XA extends A>(
fiber: Fiber.RuntimeFiber<XA, XE>,
options?:
| { readonly interruptAs?: FiberId.FiberId | undefined; readonly propagateInterruption?: boolean | undefined }
| undefined
): (self: FiberSet<A, E>) => void
<A, E, XE extends E, XA extends A>(
self: FiberSet<A, E>,
fiber: Fiber.RuntimeFiber<XA, XE>,
options?:
| { readonly interruptAs?: FiberId.FiberId | undefined; readonly propagateInterruption?: boolean | undefined }
| undefined
): void
}
Since v2.0.0