Fiber.ts overview
Since v2.0.0
Exports Grouped by Category
- alternatives
- constructors
- conversions
- destructors
- folding
- getters
- instances
- interruption
- mapping
- models
- refinements
- symbols
- utilities
- utils
- zipping
alternatives
orElse
Returns a fiber that prefers this
fiber, but falls back to the that
one when this
one fails. Interrupting the returned fiber will interrupt both fibers, sequentially, from left to right.
Signature
declare const orElse: {
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<A2 | A, E2 | E>
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<A | A2, E | E2>
}
Since v2.0.0
orElseEither
Returns a fiber that prefers this
fiber, but falls back to the that
one when this
one fails. Interrupting the returned fiber will interrupt both fibers, sequentially, from left to right.
Signature
declare const orElseEither: {
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<Either.Either<A2, A>, E2 | E>
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<Either.Either<A2, A>, E | E2>
}
Since v2.0.0
constructors
all
Collects all fibers into a single fiber producing an in-order list of the results.
Signature
declare const all: <A, E>(fibers: Iterable<Fiber<A, E>>) => Fiber<ReadonlyArray<A>, E>
Since v2.0.0
done
A fiber that is done with the specified Exit
value.
Signature
declare const done: <A, E>(exit: Exit.Exit<A, E>) => Fiber<A, E>
Since v2.0.0
fail
A fiber that has already failed with the specified value.
Signature
declare const fail: <E>(error: E) => Fiber<never, E>
Since v2.0.0
failCause
Creates a Fiber
that has already failed with the specified cause.
Signature
declare const failCause: <E>(cause: Cause.Cause<E>) => Fiber<never, E>
Since v2.0.0
interrupted
Constructrs a Fiber
that is already interrupted.
Signature
declare const interrupted: (fiberId: FiberId.FiberId) => Fiber<never>
Since v2.0.0
never
A fiber that never fails or succeeds.
Signature
declare const never: Fiber<never, never>
Since v2.0.0
roots
Returns a chunk containing all root fibers.
Signature
declare const roots: Effect.Effect<Array<RuntimeFiber<any, any>>, never, never>
Since v2.0.0
succeed
Returns a fiber that has already succeeded with the specified value.
Signature
declare const succeed: <A>(value: A) => Fiber<A>
Since v2.0.0
unsafeRoots
Returns a chunk containing all root fibers.
Signature
declare const unsafeRoots: (_: void) => Array<RuntimeFiber<any, any>>
Since v2.0.0
void
A fiber that has already succeeded with unit.
Signature
declare const void: Fiber<void, never>
Since v2.0.0
conversions
fromEffect
Lifts an Effect
into a Fiber
.
Signature
declare const fromEffect: <A, E>(effect: Effect.Effect<A, E>) => Effect.Effect<Fiber<A, E>>
Since v2.0.0
destructors
awaitAll
Awaits on all fibers to be completed, successfully or not.
Signature
declare const awaitAll: <const T extends Iterable<Fiber<any, any>>>(
fibers: T
) => Effect.Effect<
[T] extends [ReadonlyArray<infer U>]
? number extends T["length"]
? Array<U extends Fiber<infer A, infer E> ? Exit.Exit<A, E> : never>
: { -readonly [K in keyof T]: T[K] extends Fiber<infer A, infer E> ? Exit.Exit<A, E> : never }
: Array<T extends Iterable<infer U> ? (U extends Fiber<infer A, infer E> ? Exit.Exit<A, E> : never) : never>
>
Since v2.0.0
dump
Signature
declare const dump: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<Fiber.Dump>
Since v2.0.0
dumpAll
Signature
declare const dumpAll: (fibers: Iterable<RuntimeFiber<unknown, unknown>>) => Effect.Effect<Array<Fiber.Dump>>
Since v2.0.0
inheritAll
Inherits values from all FiberRef
instances into current fiber. This will resume immediately.
Signature
declare const inheritAll: <A, E>(self: Fiber<A, E>) => Effect.Effect<void>
Since v2.0.0
join
Joins the fiber, which suspends the joining fiber until the result of the fiber has been determined. Attempting to join a fiber that has erred will result in a catchable error. Joining an interrupted fiber will result in an “inner interruption” of this fiber, unlike interruption triggered by another fiber, “inner interruption” can be caught and recovered.
Signature
declare const join: <A, E>(self: Fiber<A, E>) => Effect.Effect<A, E>
Since v2.0.0
joinAll
Joins all fibers, awaiting their successful completion. Attempting to join a fiber that has erred will result in a catchable error, if that error does not result from interruption.
Signature
declare const joinAll: <A, E>(fibers: Iterable<Fiber<A, E>>) => Effect.Effect<Array<A>, E>
Since v2.0.0
pretty
Pretty-prints a RuntimeFiber
.
Signature
declare const pretty: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<string>
Since v2.0.0
scoped
Converts this fiber into a scoped effect. The fiber is interrupted when the scope is closed.
Signature
declare const scoped: <A, E>(self: Fiber<A, E>) => Effect.Effect<Fiber<A, E>, never, Scope.Scope>
Since v2.0.0
folding
match
Folds over the Fiber
or RuntimeFiber
.
Signature
declare const match: {
<A, E, Z>(options: {
readonly onFiber: (fiber: Fiber<A, E>) => Z
readonly onRuntimeFiber: (fiber: RuntimeFiber<A, E>) => Z
}): (self: Fiber<A, E>) => Z
<A, E, Z>(
self: Fiber<A, E>,
options: { readonly onFiber: (fiber: Fiber<A, E>) => Z; readonly onRuntimeFiber: (fiber: RuntimeFiber<A, E>) => Z }
): Z
}
Since v2.0.0
getters
await
Awaits the fiber, which suspends the awaiting fiber until the result of the fiber has been determined.
Signature
declare const await: <A, E>(self: Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>>
Since v2.0.0
children
Retrieves the immediate children of the fiber.
Signature
declare const children: <A, E>(self: Fiber<A, E>) => Effect.Effect<Array<RuntimeFiber<any, any>>>
Since v2.0.0
id
The identity of the fiber.
Signature
declare const id: <A, E>(self: Fiber<A, E>) => FiberId.FiberId
Since v2.0.0
poll
Tentatively observes the fiber, but returns immediately if it is not already done.
Signature
declare const poll: <A, E>(self: Fiber<A, E>) => Effect.Effect<Option.Option<Exit.Exit<A, E>>>
Since v2.0.0
status
Returns the FiberStatus
of a RuntimeFiber
.
Signature
declare const status: <A, E>(self: RuntimeFiber<A, E>) => Effect.Effect<FiberStatus.FiberStatus>
Since v2.0.0
instances
Order
Signature
declare const Order: order.Order<RuntimeFiber<unknown, unknown>>
Since v2.0.0
interruption
interrupt
Interrupts the fiber from whichever fiber is calling this method. If the fiber has already exited, the returned effect will resume immediately. Otherwise, the effect will resume when the fiber exits.
Signature
declare const interrupt: <A, E>(self: Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>>
Since v2.0.0
interruptAll
Interrupts all fibers, awaiting their interruption.
Signature
declare const interruptAll: (fibers: Iterable<Fiber<any, any>>) => Effect.Effect<void>
Since v2.0.0
interruptAllAs
Interrupts all fibers as by the specified fiber, awaiting their interruption.
Signature
declare const interruptAllAs: {
(fiberId: FiberId.FiberId): (fibers: Iterable<Fiber<any, any>>) => Effect.Effect<void>
(fibers: Iterable<Fiber<any, any>>, fiberId: FiberId.FiberId): Effect.Effect<void>
}
Since v2.0.0
interruptAs
Interrupts the fiber as if interrupted from the specified fiber. If the fiber has already exited, the returned effect will resume immediately. Otherwise, the effect will resume when the fiber exits.
Signature
declare const interruptAs: {
(fiberId: FiberId.FiberId): <A, E>(self: Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>>
<A, E>(self: Fiber<A, E>, fiberId: FiberId.FiberId): Effect.Effect<Exit.Exit<A, E>>
}
Since v2.0.0
interruptAsFork
Interrupts the fiber as if interrupted from the specified fiber. If the fiber has already exited, the returned effect will resume immediately. Otherwise, the effect will resume when the fiber exits.
Signature
declare const interruptAsFork: {
(fiberId: FiberId.FiberId): <A, E>(self: Fiber<A, E>) => Effect.Effect<void>
<A, E>(self: Fiber<A, E>, fiberId: FiberId.FiberId): Effect.Effect<void>
}
Since v2.0.0
interruptFork
Interrupts the fiber from whichever fiber is calling this method. The interruption will happen in a separate daemon fiber, and the returned effect will always resume immediately without waiting.
Signature
declare const interruptFork: <A, E>(self: Fiber<A, E>) => Effect.Effect<void>
Since v2.0.0
mapping
map
Maps over the value the Fiber computes.
Signature
declare const map: {
<A, B>(f: (a: A) => B): <E>(self: Fiber<A, E>) => Fiber<B, E>
<A, E, B>(self: Fiber<A, E>, f: (a: A) => B): Fiber<B, E>
}
Since v2.0.0
mapEffect
Effectually maps over the value the fiber computes.
Signature
declare const mapEffect: {
<A, A2, E2>(f: (a: A) => Effect.Effect<A2, E2>): <E>(self: Fiber<A, E>) => Fiber<A2, E2 | E>
<A, E, A2, E2>(self: Fiber<A, E>, f: (a: A) => Effect.Effect<A2, E2>): Fiber<A2, E | E2>
}
Since v2.0.0
mapFiber
Passes the success of this fiber to the specified callback, and continues with the fiber that it returns.
Signature
declare const mapFiber: {
<E, E2, A, B>(f: (a: A) => Fiber<B, E2>): (self: Fiber<A, E>) => Effect.Effect<Fiber<B, E | E2>>
<A, E, E2, B>(self: Fiber<A, E>, f: (a: A) => Fiber<B, E2>): Effect.Effect<Fiber<B, E | E2>>
}
Since v2.0.0
models
Fiber (interface)
A fiber is a lightweight thread of execution that never consumes more than a whole thread (but may consume much less, depending on contention and asynchronicity). Fibers are spawned by forking effects, which run concurrently with the parent effect.
Fibers can be joined, yielding their result to other fibers, or interrupted, which terminates the fiber, safely releasing all resources.
Signature
export interface Fiber<out A, out E = never> extends Effect.Effect<A, E>, Fiber.Variance<A, E> {
/**
* The identity of the fiber.
*/
id(): FiberId.FiberId
/**
* Awaits the fiber, which suspends the awaiting fiber until the result of the
* fiber has been determined.
*/
readonly await: Effect.Effect<Exit.Exit<A, E>>
/**
* Retrieves the immediate children of the fiber.
*/
readonly children: Effect.Effect<Array<Fiber.Runtime<any, any>>>
/**
* Inherits values from all `FiberRef` instances into current fiber. This
* will resume immediately.
*/
readonly inheritAll: Effect.Effect<void>
/**
* Tentatively observes the fiber, but returns immediately if it is not
* already done.
*/
readonly poll: Effect.Effect<Option.Option<Exit.Exit<A, E>>>
/**
* In the background, interrupts the fiber as if interrupted from the
* specified fiber. If the fiber has already exited, the returned effect will
* resume immediately. Otherwise, the effect will resume when the fiber exits.
*/
interruptAsFork(fiberId: FiberId.FiberId): Effect.Effect<void>
readonly [Unify.typeSymbol]?: unknown
readonly [Unify.unifySymbol]?: FiberUnify<this>
readonly [Unify.ignoreSymbol]?: FiberUnifyIgnore
}
Since v2.0.0
FiberUnify (interface)
Signature
export interface FiberUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
Fiber?: () => A[Unify.typeSymbol] extends Fiber<infer A0, infer E0> | infer _ ? Fiber<A0, E0> : never
}
Since v3.8.0
FiberUnifyIgnore (interface)
Signature
export interface FiberUnifyIgnore extends Effect.EffectUnifyIgnore {
Effect?: true
}
Since v3.8.0
RuntimeFiber (interface)
A runtime fiber that is executing an effect. Runtime fibers have an identity and a trace.
Signature
export interface RuntimeFiber<out A, out E = never> extends Fiber<A, E>, Fiber.RuntimeVariance<A, E> {
/**
* Reads the current number of ops that have occurred since the last yield
*/
get currentOpCount(): number
/**
* Reads the current value of a fiber ref
*/
getFiberRef<X>(fiberRef: FiberRef<X>): X
/**
* The identity of the fiber.
*/
id(): FiberId.Runtime
/**
* The status of the fiber.
*/
readonly status: Effect.Effect<FiberStatus.FiberStatus>
/**
* Returns the current `RuntimeFlags` the fiber is running with.
*/
readonly runtimeFlags: Effect.Effect<RuntimeFlags.RuntimeFlags>
/**
* Adds an observer to the list of observers.
*/
addObserver(observer: (exit: Exit.Exit<A, E>) => void): void
/**
* Removes the specified observer from the list of observers that will be
* notified when the fiber exits.
*/
removeObserver(observer: (exit: Exit.Exit<A, E>) => void): void
/**
* Retrieves all fiber refs of the fiber.
*/
getFiberRefs(): FiberRefs.FiberRefs
/**
* Unsafely observes the fiber, but returns immediately if it is not
* already done.
*/
unsafePoll(): Exit.Exit<A, E> | null
/**
* In the background, interrupts the fiber as if interrupted from the
* specified fiber. If the fiber has already exited, the returned effect will
* resume immediately. Otherwise, the effect will resume when the fiber exits.
*/
unsafeInterruptAsFork(fiberId: FiberId.FiberId): void
/**
* Gets the current context
*/
get currentContext(): Context<never>
/**
* Gets the current context
*/
get currentDefaultServices(): Context<DefaultServices>
/**
* Gets the current scheduler
*/
get currentScheduler(): Scheduler
/**
* Gets the current tracer
*/
get currentTracer(): Tracer
/**
* Gets the current span
*/
get currentSpan(): AnySpan | undefined
/**
* Gets the current supervisor
*/
get currentSupervisor(): Supervisor<unknown>
readonly [Unify.typeSymbol]?: unknown
readonly [Unify.unifySymbol]?: RuntimeFiberUnify<this>
readonly [Unify.ignoreSymbol]?: RuntimeFiberUnifyIgnore
}
Since v2.0.0
RuntimeFiberUnify (interface)
Signature
export interface RuntimeFiberUnify<A extends { [Unify.typeSymbol]?: any }> extends FiberUnify<A> {
RuntimeFiber?: () => A[Unify.typeSymbol] extends RuntimeFiber<infer A0, infer E0> | infer _
? RuntimeFiber<A0, E0>
: never
}
Since v3.8.0
RuntimeFiberUnifyIgnore (interface)
Signature
export interface RuntimeFiberUnifyIgnore extends FiberUnifyIgnore {
Fiber?: true
}
Since v3.8.0
refinements
isFiber
Returns true
if the specified value is a Fiber
, false
otherwise.
Signature
declare const isFiber: (u: unknown) => u is Fiber<unknown, unknown>
Since v2.0.0
isRuntimeFiber
Returns true
if the specified Fiber
is a RuntimeFiber
, false
otherwise.
Signature
declare const isRuntimeFiber: <A, E>(self: Fiber<A, E>) => self is RuntimeFiber<A, E>
Since v2.0.0
symbols
FiberTypeId
Signature
declare const FiberTypeId: unique symbol
Since v2.0.0
FiberTypeId (type alias)
Signature
type FiberTypeId = typeof FiberTypeId
Since v2.0.0
RuntimeFiberTypeId
Signature
declare const RuntimeFiberTypeId: unique symbol
Since v2.0.0
RuntimeFiberTypeId (type alias)
Signature
type RuntimeFiberTypeId = typeof RuntimeFiberTypeId
Since v2.0.0
utilities
getCurrentFiber
Gets the current fiber if one is running.
Signature
declare const getCurrentFiber: () => Option.Option<RuntimeFiber<any, any>>
Since v2.0.0
utils
Fiber (namespace)
Since v2.0.0
Variance (interface)
Signature
export interface Variance<out A, out E> {
readonly [FiberTypeId]: {
readonly _A: Types.Covariant<A>
readonly _E: Types.Covariant<E>
}
}
Since v2.0.0
RuntimeVariance (interface)
Signature
export interface RuntimeVariance<out A, out E> {
readonly [RuntimeFiberTypeId]: {
readonly _A: Types.Covariant<A>
readonly _E: Types.Covariant<E>
}
}
Since v2.0.0
Dump (interface)
Signature
export interface Dump {
/**
* The fiber's unique identifier.
*/
readonly id: FiberId.Runtime
/**
* The status of the fiber.
*/
readonly status: FiberStatus.FiberStatus
}
Since v2.0.0
Descriptor (interface)
A record containing information about a Fiber
.
Signature
export interface Descriptor {
/**
* The fiber's unique identifier.
*/
readonly id: FiberId.FiberId
/**
* The status of the fiber.
*/
readonly status: FiberStatus.FiberStatus
/**
* The set of fibers attempting to interrupt the fiber or its ancestors.
*/
readonly interruptors: HashSet.HashSet<FiberId.FiberId>
}
Since v2.0.0
Runtime (type alias)
Signature
type Runtime<A, E> = RuntimeFiber<A, E>
Since v2.0.0
zipping
zip
Zips this fiber and the specified fiber together, producing a tuple of their output.
Signature
declare const zip: {
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<[A, A2], E2 | E>
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<[A, A2], E | E2>
}
Since v2.0.0
zipLeft
Same as zip
but discards the output of that Fiber
.
Signature
declare const zipLeft: {
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<A, E2 | E>
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<A, E | E2>
}
Since v2.0.0
zipRight
Same as zip
but discards the output of this Fiber
.
Signature
declare const zipRight: {
<A2, E2>(that: Fiber<A2, E2>): <A, E>(self: Fiber<A, E>) => Fiber<A2, E2 | E>
<A, E, A2, E2>(self: Fiber<A, E>, that: Fiber<A2, E2>): Fiber<A2, E | E2>
}
Since v2.0.0
zipWith
Zips this fiber with the specified fiber, combining their results using the specified combiner function. Both joins and interruptions are performed in sequential order from left to right.
Signature
declare const zipWith: {
<B, E2, A, C>(that: Fiber<B, E2>, f: (a: A, b: B) => C): <E>(self: Fiber<A, E>) => Fiber<C, E2 | E>
<A, E, B, E2, C>(self: Fiber<A, E>, that: Fiber<B, E2>, f: (a: A, b: B) => C): Fiber<C, E | E2>
}
Since v2.0.0