/** * @tsplus type effect/core/stream/Stream/Emit */ export interface Emit extends EmitOps { (f: Effect, Chunk>): Promise } /** * @tsplus type effect/core/stream/Stream/Emit.Ops */ export interface EmitOperations {} export const Emit: EmitOperations = {} export interface EmitOps { /** * Emits a chunk containing the specified values. */ readonly chunk: (as: Chunk) => Promise /** * Terminates with a cause that dies with the specified `Throwable`. */ readonly die: (err: Err) => Promise /** * Terminates with a cause that dies with a `Throwable` with the specified * message. */ readonly dieMessage: (message: string) => Promise /** * Either emits the specified value if this `Exit` is a `Success` or else * terminates with the specified cause if this `Exit` is a `Failure`. */ readonly done: (exit: Exit) => Promise /** * Terminates with an end of stream signal. */ readonly end: () => Promise /** * Terminates with the specified error. */ readonly fail: (e: E) => Promise /** * Either emits the success value of this effect or terminates the stream * with the failure value of this effect. */ readonly fromEffect: (io: Effect) => Promise /** * Either emits the success value of this effect or terminates the stream * with the failure value of this effect. */ readonly fromEffectChunk: (io: Effect>) => Promise /** * Terminates the stream with the specified cause. */ readonly halt: (cause: Cause) => Promise /** * Emits a chunk containing the specified value. */ readonly single: (a: A) => Promise } /** * @tsplus static effect/core/stream/Stream/Emit.Ops __call */ export function apply( fn: (f: Effect, Chunk>) => Promise ): Emit { const ops: EmitOps = { chunk(this: Emit, as: Chunk) { return this(Effect.succeed(as)) }, die(this: Emit, err: Err) { return this(Effect.dieSync(err)) }, dieMessage(this: Emit, message: string) { return this(Effect.dieMessage(message)) }, done(this: Emit, exit: Exit) { return this( Effect.done( exit.mapBoth( (e) => Maybe.some(e), (a) => Chunk.single(a) ) ) ) }, end(this: Emit) { return this(Effect.fail(Maybe.none)) }, fail(this: Emit, e: E) { return this(Effect.fail(Maybe.some(e))) }, fromEffect(this: Emit, io: Effect) { return this( io.mapBoth( (e) => Maybe.some(e), (a) => Chunk.single(a) ) ) }, fromEffectChunk( this: Emit, io: Effect> ) { return this(io.mapError((e) => Maybe.some(e))) }, halt(this: Emit, cause: Cause) { return this(Effect.failCauseSync(cause.map((e) => Maybe.some(e)))) }, single(this: Emit, a: A) { return this(Effect.succeed(Chunk.single(a))) } } return Object.assign(fn, ops) }