/** * @since 1.0.0 */ import type * as Either from "@effect/data/Either"; import type * as HashSet from "@effect/data/HashSet"; import type * as Option from "@effect/data/Option"; import type * as order from "@effect/data/Order"; import type { Pipeable } from "@effect/data/Pipeable"; import type * as Cause from "@effect/io/Cause"; import type * as Effect from "@effect/io/Effect"; import type * as Exit from "@effect/io/Exit"; import type * as FiberId from "@effect/io/FiberId"; import type { FiberRef } from "@effect/io/FiberRef"; import type * as FiberRefs from "@effect/io/FiberRefs"; import type * as FiberStatus from "@effect/io/FiberStatus"; import type * as RuntimeFlags from "@effect/io/RuntimeFlags"; import type * as Scope from "@effect/io/Scope"; /** * @since 1.0.0 * @category symbols */ export declare const FiberTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type FiberTypeId = typeof FiberTypeId; /** * @since 1.0.0 * @category symbols */ export declare const RuntimeFiberTypeId: unique symbol; /** * @since 1.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 1.0.0 * @category models */ export interface Fiber extends Fiber.Variance, Pipeable { /** * 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. */ await(): Effect.Effect>; /** * Retrieves the immediate children of the fiber. */ children(): Effect.Effect>>; /** * Inherits values from all `FiberRef` instances into current fiber. This * will resume immediately. */ inheritAll(): Effect.Effect; /** * Tentatively observes the fiber, but returns immediately if it is not * already done. */ 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; } /** * A runtime fiber that is executing an effect. Runtime fibers have an * identity and a trace. * * @since 1.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. */ status(): Effect.Effect; /** * Returns the current `RuntimeFlags` the fiber is running with. */ 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; } /** * @since 1.0.0 */ export declare namespace Fiber { /** * @since 1.0.0 * @category models */ type Runtime = RuntimeFiber; /** * @since 1.0.0 * @category models */ interface Variance { readonly [FiberTypeId]: { readonly _E: (_: never) => E; readonly _A: (_: never) => A; }; } /** * @since 1.0.0 */ interface RuntimeVariance { readonly [RuntimeFiberTypeId]: { readonly _E: (_: never) => E; readonly _A: (_: never) => A; }; } /** * @since 1.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 1.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 1.0.0 * @category instances */ export declare const Order: order.Order>; /** * Returns `true` if the specified value is a `Fiber`, `false` otherwise. * * @since 1.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 1.0.0 * @category refinements */ export declare const isRuntimeFiber: (self: Fiber) => self is RuntimeFiber; /** * The identity of the fiber. * * @since 1.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 1.0.0 * @category getters */ _await as await }; /** * Awaits on all fibers to be completed, successfully or not. * * @since 1.0.0 * @category destructors */ export declare const awaitAll: (fibers: Iterable>) => Effect.Effect; /** * Retrieves the immediate children of the fiber. * * @since 1.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 1.0.0 * @category constructors */ export declare const all: (fibers: Iterable>) => Fiber>; /** * A fiber that is done with the specified `Exit` value. * * @since 1.0.0 * @category constructors */ export declare const done: (exit: Exit.Exit) => Fiber; /** * @since 1.0.0 * @category destructors */ export declare const dump: (self: RuntimeFiber) => Effect.Effect; /** * @since 1.0.0 * @category destructors */ export declare const dumpAll: (fibers: Iterable>) => Effect.Effect>; /** * A fiber that has already failed with the specified value. * * @since 1.0.0 * @category constructors */ export declare const fail: (error: E) => Fiber; /** * Creates a `Fiber` that has already failed with the specified cause. * * @since 1.0.0 * @category constructors */ export declare const failCause: (cause: Cause.Cause) => Fiber; /** * Lifts an `Effect` into a `Fiber`. * * @since 1.0.0 * @category conversions */ export declare const fromEffect: (effect: Effect.Effect) => Effect.Effect>; /** * Gets the current fiber if one is running. * * @since 1.0.0 * @category utilities */ export declare const getCurrentFiber: () => Option.Option>; /** * Inherits values from all `FiberRef` instances into current fiber. This * will resume immediately. * * @since 1.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 1.0.0 * @category interruption */ export declare const interrupt: (self: Fiber) => Effect.Effect>; /** * Constructrs a `Fiber` that is already interrupted. * * @since 1.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 1.0.0 * @category interruption */ export declare const interruptAs: { (fiberId: FiberId.FiberId): (self: Fiber) => Effect.Effect>; (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 1.0.0 * @category interruption */ export declare const interruptAsFork: { (fiberId: FiberId.FiberId): (self: Fiber) => Effect.Effect; (self: Fiber, fiberId: FiberId.FiberId): Effect.Effect; }; /** * Interrupts all fibers, awaiting their interruption. * * @since 1.0.0 * @category interruption */ export declare const interruptAll: (fibers: Iterable>) => Effect.Effect; /** * Interrupts all fibers as by the specified fiber, awaiting their * interruption. * * @since 1.0.0 * @category interruption */ export declare const interruptAllAs: { (fiberId: FiberId.FiberId): (fibers: Iterable>) => Effect.Effect; (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 1.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 1.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 1.0.0 * @category destructors */ export declare const joinAll: (fibers: Iterable>) => Effect.Effect; /** * Maps over the value the Fiber computes. * * @since 1.0.0 * @category mapping */ export declare const map: { (f: (a: A) => B): (self: Fiber) => Fiber; (self: Fiber, f: (a: A) => B): Fiber; }; /** * Effectually maps over the value the fiber computes. * * @since 1.0.0 * @category mapping */ export declare const mapEffect: { (f: (a: A) => Effect.Effect): (self: Fiber) => Fiber; (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 1.0.0 * @category mapping */ export declare const mapFiber: { (f: (a: A) => Fiber): (self: Fiber) => Effect.Effect>; (self: Fiber, f: (a: A) => Fiber): Effect.Effect>; }; /** * Folds over the `Fiber` or `RuntimeFiber`. * * @since 1.0.0 * @category folding */ export declare const match: { (options: { readonly onFiber: (fiber: Fiber) => Z; readonly onRuntimeFiber: (fiber: RuntimeFiber) => Z; }): (self: Fiber) => Z; (self: Fiber, options: { readonly onFiber: (fiber: Fiber) => Z; readonly onRuntimeFiber: (fiber: RuntimeFiber) => Z; }): Z; }; /** * A fiber that never fails or succeeds. * * @since 1.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 1.0.0 * @category alternatives */ export declare const orElse: { (that: Fiber): (self: Fiber) => Fiber; (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 1.0.0 * @category alternatives */ export declare const orElseEither: { (that: Fiber): (self: Fiber) => Fiber>; (self: Fiber, that: Fiber): Fiber>; }; /** * Tentatively observes the fiber, but returns immediately if it is not * already done. * * @since 1.0.0 * @category getters */ export declare const poll: (self: Fiber) => Effect.Effect>>; /** * Pretty-prints a `RuntimeFiber`. * * @since 1.0.0 * @category destructors */ export declare const pretty: (self: RuntimeFiber) => Effect.Effect; /** * Returns a chunk containing all root fibers. * * @since 1.0.0 * @category constructors */ export declare const roots: Effect.Effect>>; /** * Returns a chunk containing all root fibers. * * @since 1.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 1.0.0 * @category destructors */ export declare const scoped: (self: Fiber) => Effect.Effect>; /** * Returns the `FiberStatus` of a `RuntimeFiber`. * * @since 1.0.0 * @category getters */ export declare const status: (self: RuntimeFiber) => Effect.Effect; /** * Returns a fiber that has already succeeded with the specified value. * * @since 1.0.0 * @category constructors */ export declare const succeed: (value: A) => Fiber; /** * A fiber that has already succeeded with unit. * * @since 1.0.0 * @category constructors */ export declare const unit: Fiber; /** * Zips this fiber and the specified fiber together, producing a tuple of * their output. * * @since 1.0.0 * @category zipping */ export declare const zip: { (that: Fiber): (self: Fiber) => Fiber; (self: Fiber, that: Fiber): Fiber; }; /** * Same as `zip` but discards the output of that `Fiber`. * * @since 1.0.0 * @category zipping */ export declare const zipLeft: { (that: Fiber): (self: Fiber) => Fiber; (self: Fiber, that: Fiber): Fiber; }; /** * Same as `zip` but discards the output of this `Fiber`. * * @since 1.0.0 * @category zipping */ export declare const zipRight: { (that: Fiber): (self: Fiber) => Fiber; (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 1.0.0 * @category zipping */ export declare const zipWith: { (that: Fiber, f: (a: A, b: B) => C): (self: Fiber) => Fiber; (self: Fiber, that: Fiber, f: (a: A, b: B) => C): Fiber; }; //# sourceMappingURL=Fiber.d.ts.map