import type { ChildExecutorDecision } from "@effect/core/stream/Channel/ChildExecutorDecision" import type { Channel } from "@effect/core/stream/Channel/definition/base" import { ChannelBase } from "@effect/core/stream/Channel/definition/base" import { _Env, _InDone, _InElem, _InErr, _OutDone, _OutDone2, _OutElem, _OutErr, _OutErr2 } from "@effect/core/stream/Channel/definition/symbols" import type { AsyncInputProducer } from "@effect/core/stream/Channel/SingleProducerAsyncInput" import type { UpstreamPullRequest } from "@effect/core/stream/Channel/UpstreamPullRequest" import type { UpstreamPullStrategy } from "@effect/core/stream/Channel/UpstreamPullStrategy" // ----------------------------------------------------------------------------- // PipeTo // ----------------------------------------------------------------------------- export class PipeTo< Env, InErr, InElem, InDone, OutErr2, OutElem2, OutDone2, OutErr, OutElem, OutDone > extends ChannelBase { readonly _tag = "PipeTo" constructor( readonly left: Lazy>, readonly right: Lazy< Channel > ) { super() } } // ----------------------------------------------------------------------------- // Read // ----------------------------------------------------------------------------- export class Read< Env, InErr, InElem, InDone, OutErr2, OutElem, OutDone2, OutErr, OutDone > extends ChannelBase { readonly _tag = "Read" constructor( readonly more: ( i: InElem ) => Channel, readonly done: ContinuationK< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > ) { super() } } // ----------------------------------------------------------------------------- // SucceedNow // ----------------------------------------------------------------------------- export class SucceedNow extends ChannelBase< never, unknown, unknown, unknown, never, never, OutDone > { readonly _tag = "SucceedNow" constructor(readonly terminal: OutDone) { super() } } // ----------------------------------------------------------------------------- // Fail // ----------------------------------------------------------------------------- export class Fail extends ChannelBase< never, unknown, unknown, unknown, OutErr, never, never > { readonly _tag = "Fail" constructor(readonly error: Lazy>) { super() } } // ----------------------------------------------------------------------------- // FromEffect // ----------------------------------------------------------------------------- export class FromEffect extends ChannelBase< Env, unknown, unknown, unknown, OutErr, never, OutDone > { readonly _tag = "FromEffect" constructor(readonly effect: Effect) { super() } } // ----------------------------------------------------------------------------- // Emit // ----------------------------------------------------------------------------- export class Emit extends ChannelBase< never, unknown, unknown, unknown, never, OutElem, OutDone > { readonly _tag = "Emit" constructor(readonly out: OutElem) { super() } } // ----------------------------------------------------------------------------- // Succeed // ----------------------------------------------------------------------------- export class Succeed extends ChannelBase< never, unknown, unknown, unknown, never, never, OutDone > { readonly _tag = "Succeed" constructor(readonly effect: Lazy) { super() } } // ----------------------------------------------------------------------------- // Suspend // ----------------------------------------------------------------------------- export class Suspend< Env, InErr, InElem, InDone, OutErr, OutElem, OutDone > extends ChannelBase { readonly _tag = "Suspend" constructor( readonly effect: Lazy> ) { super() } } // ----------------------------------------------------------------------------- // Ensuring // ----------------------------------------------------------------------------- export class Ensuring< Env, InErr, InElem, InDone, OutErr, OutElem, OutDone > extends ChannelBase { readonly _tag = "Ensuring" constructor( readonly channel: Channel, readonly finalizer: (exit: Exit) => Effect ) { super() } } // ----------------------------------------------------------------------------- // ConcatAll // ----------------------------------------------------------------------------- export class ConcatAll< Env, InErr, InElem, InDone, OutErr, OutElem2, OutDone3, OutElem, OutDone, OutDone2 > extends ChannelBase { readonly _tag = "ConcatAll" constructor( readonly combineInners: (x: OutDone, y: OutDone) => OutDone, readonly combineAll: (x: OutDone, y: OutDone2) => OutDone3, readonly onPull: ( pr: UpstreamPullRequest ) => UpstreamPullStrategy, readonly onEmit: (o: OutElem2) => ChildExecutorDecision, readonly value: Lazy< Channel >, readonly k: ( o: OutElem ) => Channel ) { super() } } // ----------------------------------------------------------------------------- // Fold // ----------------------------------------------------------------------------- export class Fold< Env, InErr, InElem, InDone, OutErr2, OutElem, OutDone2, OutErr, OutDone > extends ChannelBase { readonly _tag = "Fold" constructor( readonly value: Channel, readonly k: ContinuationK< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > ) { super() } } // ----------------------------------------------------------------------------- // Bridge // ----------------------------------------------------------------------------- export class Bridge< Env, InErr, InElem, InDone, OutErr, OutElem, OutDone > extends ChannelBase { readonly _tag = "Bridge" constructor( readonly input: AsyncInputProducer, readonly channel: Channel ) { super() } } // ----------------------------------------------------------------------------- // BracketOut // ----------------------------------------------------------------------------- export class BracketOut extends ChannelBase< R, unknown, unknown, unknown, E, Z, OutDone > { readonly _tag = "BracketOut" constructor( readonly acquire: Lazy>, readonly finalizer: (z: Z, exit: Exit) => Effect ) { super() } } // ----------------------------------------------------------------------------- // Provide // ----------------------------------------------------------------------------- export class Provide< R, InErr, InElem, InDone, OutErr, OutElem, OutDone > extends ChannelBase { readonly _tag = "Provide" constructor( readonly env: Env, readonly channel: Channel ) { super() } } /** * @tsplus macro remove */ export function concrete( _: Channel ): asserts _ is | PipeTo | Read | SucceedNow | Fail | FromEffect | Emit | Succeed | Suspend | Ensuring | ConcatAll | Fold | Bridge | BracketOut | Provide { // } // ----------------------------------------------------------------------------- // Continuation // ----------------------------------------------------------------------------- export abstract class Continuation< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > { readonly [_Env]!: () => Env readonly [_InErr]!: (_: InErr) => void readonly [_InElem]!: (_: InElem) => void readonly [_InDone]!: (_: InDone) => void readonly [_OutErr]!: (_: OutErr) => OutErr readonly [_OutDone]!: (_: OutDone) => OutDone readonly [_OutErr2]!: () => OutErr2 readonly [_OutElem]!: () => OutElem readonly [_OutDone2]!: () => OutDone2 } /** * @tsplus macro remove */ export function concreteContinuation< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 >( _: Continuation< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > ): asserts _ is | ContinuationK< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > | ContinuationFinalizer { // } export class ContinuationK< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > extends Continuation< Env, InErr, InElem, InDone, OutErr, OutErr2, OutElem, OutDone, OutDone2 > { readonly _tag = "ContinuationK" constructor( readonly onSuccess: ( o: OutDone ) => Channel, readonly onHalt: ( c: Cause ) => Channel ) { super() } onExit( exit: Exit ): Channel { switch (exit._tag) { case "Failure": { return this.onHalt(exit.cause) } case "Success": { return this.onSuccess(exit.value) } } } } export class ContinuationFinalizer extends Continuation< Env, unknown, unknown, unknown, OutErr, never, never, OutDone, never > { readonly _tag = "ContinuationFinalizer" constructor(readonly finalizer: (exit: Exit) => Effect) { super() } }