/** * @since 2.0.0 */ import type * as Cause from "./Cause.js"; import type { Context } from "./Context.js"; import type { DefaultServices } from "./DefaultServices.js"; import type * as Effect from "./Effect.js"; import type * as Either from "./Either.js"; import type * as Exit from "./Exit.js"; import type * as FiberId from "./FiberId.js"; import type { FiberRef } from "./FiberRef.js"; import type * as FiberRefs from "./FiberRefs.js"; import type * as FiberStatus from "./FiberStatus.js"; import type * as HashSet from "./HashSet.js"; import type * as Option from "./Option.js"; import type * as order from "./Order.js"; import type * as RuntimeFlags from "./RuntimeFlags.js"; import type { Scheduler } from "./Scheduler.js"; import type * as Scope from "./Scope.js"; import type { Supervisor } from "./Supervisor.js"; import type { AnySpan, Tracer } from "./Tracer.js"; import type * as Types from "./Types.js"; import type * as Unify from "./Unify.js"; /** * @since 2.0.0 * @category symbols */ export declare const FiberTypeId: unique symbol; /** * @since 2.0.0 * @category symbols */ export type FiberTypeId = typeof FiberTypeId; /** * @since 2.0.0 * @category symbols */ export declare const RuntimeFiberTypeId: unique symbol; /** * @since 2.0.0 * @category symbols */ export type RuntimeFiberTypeId = typeof RuntimeFiberTypeId; /** * 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. * * @since 2.0.0 * @category models */ export interface Fiber extends Effect.Effect, Fiber.Variance { /** * 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>; /** * Retrieves the immediate children of the fiber. */ readonly children: Effect.Effect>>; /** * Inherits values from all `FiberRef` instances into current fiber. This * will resume immediately. */ readonly inheritAll: Effect.Effect; /** * Tentatively observes the fiber, but returns immediately if it is not * already done. */ readonly poll: Effect.Effect>>; /** * 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; readonly [Unify.typeSymbol]?: unknown; readonly [Unify.unifySymbol]?: FiberUnify; readonly [Unify.ignoreSymbol]?: FiberUnifyIgnore; } /** * @category models * @since 3.8.0 */ export interface FiberUnify extends Effect.EffectUnify { Fiber?: () => A[Unify.typeSymbol] extends Fiber | infer _ ? Fiber : never; } /** * @category models * @since 3.8.0 */ export interface FiberUnifyIgnore extends Effect.EffectUnifyIgnore { Effect?: true; } /** * A runtime fiber that is executing an effect. Runtime fibers have an * identity and a trace. * * @since 2.0.0 * @category models */ export interface RuntimeFiber extends Fiber, Fiber.RuntimeVariance { /** * 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(fiberRef: FiberRef): X; /** * The identity of the fiber. */ id(): FiberId.Runtime; /** * The status of the fiber. */ readonly status: Effect.Effect; /** * Returns the current `RuntimeFlags` the fiber is running with. */ readonly runtimeFlags: Effect.Effect; /** * Adds an observer to the list of observers. */ addObserver(observer: (exit: Exit.Exit) => void): void; /** * Removes the specified observer from the list of observers that will be * notified when the fiber exits. */ removeObserver(observer: (exit: Exit.Exit) => 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 | 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; /** * Gets the current context */ get currentDefaultServices(): Context; /** * 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; readonly [Unify.typeSymbol]?: unknown; readonly [Unify.unifySymbol]?: RuntimeFiberUnify; readonly [Unify.ignoreSymbol]?: RuntimeFiberUnifyIgnore; } /** * @category models * @since 3.8.0 */ export interface RuntimeFiberUnify extends FiberUnify { RuntimeFiber?: () => A[Unify.typeSymbol] extends RuntimeFiber | infer _ ? RuntimeFiber : never; } /** * @category models * @since 3.8.0 */ export interface RuntimeFiberUnifyIgnore extends FiberUnifyIgnore { Fiber?: true; } /** * @since 2.0.0 */ export declare namespace Fiber { /** * @since 2.0.0 * @category models */ type Runtime = RuntimeFiber; /** * @since 2.0.0 * @category models */ interface Variance { readonly [FiberTypeId]: { readonly _A: Types.Covariant; readonly _E: Types.Covariant; }; } /** * @since 2.0.0 */ interface RuntimeVariance { readonly [RuntimeFiberTypeId]: { readonly _A: Types.Covariant; readonly _E: Types.Covariant; }; } /** * @since 2.0.0 * @category models */ interface Dump { /** * The fiber's unique identifier. */ readonly id: FiberId.Runtime; /** * The status of the fiber. */ readonly status: FiberStatus.FiberStatus; } /** * A record containing information about a `Fiber`. * * @since 2.0.0 * @category models */ 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; } } /** * @since 2.0.0 * @category instances */ export declare const Order: order.Order>; /** * Returns `true` if the specified value is a `Fiber`, `false` otherwise. * * @since 2.0.0 * @category refinements */ export declare const isFiber: (u: unknown) => u is Fiber; /** * Returns `true` if the specified `Fiber` is a `RuntimeFiber`, `false` * otherwise. * * @since 2.0.0 * @category refinements */ export declare const isRuntimeFiber: (self: Fiber) => self is RuntimeFiber; /** * The identity of the fiber. * * @since 2.0.0 * @category getters */ export declare const id: (self: Fiber) => FiberId.FiberId; declare const _await: (self: Fiber) => Effect.Effect>; export { /** * Awaits the fiber, which suspends the awaiting fiber until the result of the * fiber has been determined. * * @since 2.0.0 * @category getters */ _await as await }; /** * Awaits on all fibers to be completed, successfully or not. * * @since 2.0.0 * @category destructors */ export declare const awaitAll: >>(fibers: T) => Effect.Effect<[ T ] extends [ReadonlyArray] ? number extends T["length"] ? Array ? Exit.Exit : never> : { -readonly [K in keyof T]: T[K] extends Fiber ? Exit.Exit : never; } : Array ? U extends Fiber ? Exit.Exit : never : never>>; /** * Retrieves the immediate children of the fiber. * * @since 2.0.0 * @category getters */ export declare const children: (self: Fiber) => Effect.Effect>>; /** * Collects all fibers into a single fiber producing an in-order list of the * results. * * @since 2.0.0 * @category constructors */ export declare const all: (fibers: Iterable>) => Fiber, E>; /** * A fiber that is done with the specified `Exit` value. * * @since 2.0.0 * @category constructors */ export declare const done: (exit: Exit.Exit) => Fiber; /** * @since 2.0.0 * @category destructors */ export declare const dump: (self: RuntimeFiber) => Effect.Effect; /** * @since 2.0.0 * @category destructors */ export declare const dumpAll: (fibers: Iterable>) => Effect.Effect>; /** * A fiber that has already failed with the specified value. * * @since 2.0.0 * @category constructors */ export declare const fail: (error: E) => Fiber; /** * Creates a `Fiber` that has already failed with the specified cause. * * @since 2.0.0 * @category constructors */ export declare const failCause: (cause: Cause.Cause) => Fiber; /** * Lifts an `Effect` into a `Fiber`. * * @since 2.0.0 * @category conversions */ export declare const fromEffect: (effect: Effect.Effect) => Effect.Effect>; /** * Gets the current fiber if one is running. * * @since 2.0.0 * @category utilities */ export declare const getCurrentFiber: () => Option.Option>; /** * Inherits values from all `FiberRef` instances into current fiber. This * will resume immediately. * * @since 2.0.0 * @category destructors */ export declare const inheritAll: (self: Fiber) => Effect.Effect; /** * 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. * * @since 2.0.0 * @category interruption */ export declare const interrupt: (self: Fiber) => Effect.Effect>; /** * Constructrs a `Fiber` that is already interrupted. * * @since 2.0.0 * @category constructors */ export declare const interrupted: (fiberId: FiberId.FiberId) => Fiber; /** * 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. * * @since 2.0.0 * @category interruption */ export declare const 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. * * @since 2.0.0 * @category interruption */ (fiberId: FiberId.FiberId): (self: Fiber) => Effect.Effect>; /** * 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. * * @since 2.0.0 * @category interruption */ (self: Fiber, fiberId: FiberId.FiberId): Effect.Effect>; }; /** * 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. * * @since 2.0.0 * @category interruption */ export declare const 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. * * @since 2.0.0 * @category interruption */ (fiberId: FiberId.FiberId): (self: Fiber) => Effect.Effect; /** * 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. * * @since 2.0.0 * @category interruption */ (self: Fiber, fiberId: FiberId.FiberId): Effect.Effect; }; /** * Interrupts all fibers, awaiting their interruption. * * @since 2.0.0 * @category interruption */ export declare const interruptAll: (fibers: Iterable>) => Effect.Effect; /** * Interrupts all fibers as by the specified fiber, awaiting their * interruption. * * @since 2.0.0 * @category interruption */ export declare const interruptAllAs: { /** * Interrupts all fibers as by the specified fiber, awaiting their * interruption. * * @since 2.0.0 * @category interruption */ (fiberId: FiberId.FiberId): (fibers: Iterable>) => Effect.Effect; /** * Interrupts all fibers as by the specified fiber, awaiting their * interruption. * * @since 2.0.0 * @category interruption */ (fibers: Iterable>, fiberId: FiberId.FiberId): Effect.Effect; }; /** * 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. * * @since 2.0.0 * @category interruption */ export declare const interruptFork: (self: Fiber) => Effect.Effect; /** * 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. * * @since 2.0.0 * @category destructors */ export declare const join: (self: Fiber) => Effect.Effect; /** * 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. * * @since 2.0.0 * @category destructors */ export declare const joinAll: (fibers: Iterable>) => Effect.Effect, E>; /** * Maps over the value the Fiber computes. * * @since 2.0.0 * @category mapping */ export declare const map: { /** * Maps over the value the Fiber computes. * * @since 2.0.0 * @category mapping */ (f: (a: A) => B): (self: Fiber) => Fiber; /** * Maps over the value the Fiber computes. * * @since 2.0.0 * @category mapping */ (self: Fiber, f: (a: A) => B): Fiber; }; /** * Effectually maps over the value the fiber computes. * * @since 2.0.0 * @category mapping */ export declare const mapEffect: { /** * Effectually maps over the value the fiber computes. * * @since 2.0.0 * @category mapping */ (f: (a: A) => Effect.Effect): (self: Fiber) => Fiber; /** * Effectually maps over the value the fiber computes. * * @since 2.0.0 * @category mapping */ (self: Fiber, f: (a: A) => Effect.Effect): Fiber; }; /** * Passes the success of this fiber to the specified callback, and continues * with the fiber that it returns. * * @since 2.0.0 * @category mapping */ export declare const mapFiber: { /** * Passes the success of this fiber to the specified callback, and continues * with the fiber that it returns. * * @since 2.0.0 * @category mapping */ (f: (a: A) => Fiber): (self: Fiber) => Effect.Effect>; /** * Passes the success of this fiber to the specified callback, and continues * with the fiber that it returns. * * @since 2.0.0 * @category mapping */ (self: Fiber, f: (a: A) => Fiber): Effect.Effect>; }; /** * Folds over the `Fiber` or `RuntimeFiber`. * * @since 2.0.0 * @category folding */ export declare const match: { /** * Folds over the `Fiber` or `RuntimeFiber`. * * @since 2.0.0 * @category folding */ (options: { readonly onFiber: (fiber: Fiber) => Z; readonly onRuntimeFiber: (fiber: RuntimeFiber) => Z; }): (self: Fiber) => Z; /** * Folds over the `Fiber` or `RuntimeFiber`. * * @since 2.0.0 * @category folding */ (self: Fiber, options: { readonly onFiber: (fiber: Fiber) => Z; readonly onRuntimeFiber: (fiber: RuntimeFiber) => Z; }): Z; }; /** * A fiber that never fails or succeeds. * * @since 2.0.0 * @category constructors */ export declare const never: Fiber; /** * 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. * * @since 2.0.0 * @category alternatives */ export declare const 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. * * @since 2.0.0 * @category alternatives */ (that: Fiber): (self: Fiber) => Fiber; /** * 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. * * @since 2.0.0 * @category alternatives */ (self: Fiber, that: Fiber): Fiber; }; /** * 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. * * @since 2.0.0 * @category alternatives */ export declare const 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. * * @since 2.0.0 * @category alternatives */ (that: Fiber): (self: Fiber) => Fiber, E2 | E>; /** * 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. * * @since 2.0.0 * @category alternatives */ (self: Fiber, that: Fiber): Fiber, E | E2>; }; /** * Tentatively observes the fiber, but returns immediately if it is not * already done. * * @since 2.0.0 * @category getters */ export declare const poll: (self: Fiber) => Effect.Effect>>; /** * Pretty-prints a `RuntimeFiber`. * * @since 2.0.0 * @category destructors */ export declare const pretty: (self: RuntimeFiber) => Effect.Effect; /** * Returns a chunk containing all root fibers. * * @since 2.0.0 * @category constructors */ export declare const roots: Effect.Effect>>; /** * Returns a chunk containing all root fibers. * * @since 2.0.0 * @category constructors */ export declare const unsafeRoots: (_: void) => Array>; /** * Converts this fiber into a scoped effect. The fiber is interrupted when the * scope is closed. * * @since 2.0.0 * @category destructors */ export declare const scoped: (self: Fiber) => Effect.Effect, never, Scope.Scope>; /** * Returns the `FiberStatus` of a `RuntimeFiber`. * * @since 2.0.0 * @category getters */ export declare const status: (self: RuntimeFiber) => Effect.Effect; /** * Returns a fiber that has already succeeded with the specified value. * * @since 2.0.0 * @category constructors */ export declare const succeed: (value: A) => Fiber; declare const void_: Fiber; export { /** * A fiber that has already succeeded with unit. * * @since 2.0.0 * @category constructors */ void_ as void }; /** * Zips this fiber and the specified fiber together, producing a tuple of * their output. * * @since 2.0.0 * @category zipping */ export declare const zip: { /** * Zips this fiber and the specified fiber together, producing a tuple of * their output. * * @since 2.0.0 * @category zipping */ (that: Fiber): (self: Fiber) => Fiber<[A, A2], E2 | E>; /** * Zips this fiber and the specified fiber together, producing a tuple of * their output. * * @since 2.0.0 * @category zipping */ (self: Fiber, that: Fiber): Fiber<[A, A2], E | E2>; }; /** * Same as `zip` but discards the output of that `Fiber`. * * @since 2.0.0 * @category zipping */ export declare const zipLeft: { /** * Same as `zip` but discards the output of that `Fiber`. * * @since 2.0.0 * @category zipping */ (that: Fiber): (self: Fiber) => Fiber; /** * Same as `zip` but discards the output of that `Fiber`. * * @since 2.0.0 * @category zipping */ (self: Fiber, that: Fiber): Fiber; }; /** * Same as `zip` but discards the output of this `Fiber`. * * @since 2.0.0 * @category zipping */ export declare const zipRight: { /** * Same as `zip` but discards the output of this `Fiber`. * * @since 2.0.0 * @category zipping */ (that: Fiber): (self: Fiber) => Fiber; /** * Same as `zip` but discards the output of this `Fiber`. * * @since 2.0.0 * @category zipping */ (self: Fiber, that: Fiber): Fiber; }; /** * 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. * * @since 2.0.0 * @category zipping */ export declare const 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. * * @since 2.0.0 * @category zipping */ (that: Fiber, f: (a: A, b: B) => C): (self: Fiber) => Fiber; /** * 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. * * @since 2.0.0 * @category zipping */ (self: Fiber, that: Fiber, f: (a: A, b: B) => C): Fiber; }; //# sourceMappingURL=Fiber.d.ts.map