/** * A `Supervisor` is allowed to supervise the launching and termination of * fibers, producing some visible value of type `T` from the supervision. * * @since 1.0.0 */ import type * as Context from "@effect/data/Context" import type * as MutableRef from "@effect/data/MutableRef" import type * as Option from "@effect/data/Option" import type * as SortedSet from "@effect/data/SortedSet" import type * as Effect from "@effect/io/Effect" import type * as Exit from "@effect/io/Exit" import type * as Fiber from "@effect/io/Fiber" import * as core from "@effect/io/internal/core" import * as circular from "@effect/io/internal/layer/circular" import * as internal from "@effect/io/internal/supervisor" import type * as Layer from "@effect/io/Layer" /** * @since 1.0.0 * @category symbols */ export const SupervisorTypeId: unique symbol = internal.SupervisorTypeId /** * @since 1.0.0 * @category symbols */ export type SupervisorTypeId = typeof SupervisorTypeId /** * @since 1.0.0 * @category models */ export interface Supervisor extends Supervisor.Variance { /** * Returns an `Effect` that succeeds with the value produced by this * supervisor. This value may change over time, reflecting what the supervisor * produces as it supervises fibers. */ value(): Effect.Effect /** * Supervises the start of a `Fiber`. */ onStart( context: Context.Context, effect: Effect.Effect, parent: Option.Option>, fiber: Fiber.RuntimeFiber ): void /** * Supervises the end of a `Fiber`. */ onEnd(value: Exit.Exit, fiber: Fiber.RuntimeFiber): void /** * Supervises the execution of an `Effect` by a `Fiber`. */ onEffect(fiber: Fiber.RuntimeFiber, effect: Effect.Effect): void /** * Supervises the suspension of a computation running within a `Fiber`. */ onSuspend(fiber: Fiber.RuntimeFiber): void /** * Supervises the resumption of a computation running within a `Fiber`. */ onResume(fiber: Fiber.RuntimeFiber): void /** * Maps this supervisor to another one, which has the same effect, but whose * value has been transformed by the specified function. */ map(f: (a: T) => B): Supervisor /** * Returns a new supervisor that performs the function of this supervisor, and * the function of the specified supervisor, producing a tuple of the outputs * produced by both supervisors. */ zip(right: Supervisor): Supervisor } /** * @since 1.0.0 */ export declare namespace Supervisor { /** * @since 1.0.0 * @category models */ export interface Variance { readonly [SupervisorTypeId]: { readonly _T: (_: never) => T } } } /** * @since 1.0.0 * @category context */ export const addSupervisor: (supervisor: Supervisor) => Layer.Layer = circular.addSupervisor /** * Creates a new supervisor that tracks children in a set. * * @since 1.0.0 * @category constructors */ export const fibersIn: ( ref: MutableRef.MutableRef>> ) => Effect.Effect>>> = internal.fibersIn /** * Creates a new supervisor that constantly yields effect when polled * * @since 1.0.0 * @category constructors */ export const fromEffect: (effect: Effect.Effect) => Supervisor = internal.fromEffect /** * A supervisor that doesn't do anything in response to supervision events. * * @since 1.0.0 * @category constructors */ export const none: Supervisor = internal.none /** * Creates a new supervisor that tracks children in a set. * * @since 1.0.0 * @category constructors */ export const track: Effect.Effect>>> = internal.track /** * Unsafely creates a new supervisor that tracks children in a set. * * @since 1.0.0 * @category unsafe */ export const unsafeTrack: () => Supervisor>> = internal.unsafeTrack /** * @since 1.0.0 * @category constructors */ export abstract class AbstractSupervisor implements Supervisor { /** * @since 1.0.0 */ abstract value(): Effect.Effect /** * @since 1.0.0 */ onStart( _context: Context.Context, _effect: Effect.Effect, _parent: Option.Option>, _fiber: Fiber.RuntimeFiber ): void { // } /** * @since 1.0.0 */ onEnd( _value: Exit.Exit, _fiber: Fiber.RuntimeFiber ): void { // } /** * @since 1.0.0 */ onEffect( _fiber: Fiber.RuntimeFiber, _effect: Effect.Effect ): void { // } /** * @since 1.0.0 */ onSuspend( _fiber: Fiber.RuntimeFiber ): void { // } /** * @since 1.0.0 */ onResume( _fiber: Fiber.RuntimeFiber ): void { // } /** * @since 1.0.0 */ map(f: (a: T) => B): Supervisor { return new internal.ProxySupervisor(this, () => core.map(this.value(), f)) } /** * @since 1.0.0 */ zip( right: Supervisor ): Supervisor { return new internal.Zip(this, right) } /** * @since 1.0.0 */ onRun(execution: () => X, _fiber: Fiber.RuntimeFiber): X { return execution() } /** * @since 1.0.0 */ readonly [SupervisorTypeId]: { _T: (_: never) => never } = internal.supervisorVariance }