/** * @since 2.0.0 */ import type * as Cause from "./Cause.js" import type * as Effect from "./Effect.js" import type * as Either from "./Either.js" import type * as Exit from "./Exit.js" import * as internal from "./internal/channel/singleProducerAsyncInput.js" /** * An MVar-like abstraction for sending data to channels asynchronously which is * designed for one producer and multiple consumers. * * Features the following semantics: * - Buffer of size 1. * - When emitting, the producer waits for a consumer to pick up the value to * prevent "reading ahead" too much. * - Once an emitted element is read by a consumer, it is cleared from the * buffer, so that at most one consumer sees every emitted element. * - When sending a done or error signal, the producer does not wait for a * consumer to pick up the signal. The signal stays in the buffer after * being read by a consumer, so it can be propagated to multiple consumers. * - Trying to publish another emit/error/done after an error/done have * already been published results in an interruption. * * @since 2.0.0 * @category models */ export interface SingleProducerAsyncInput extends AsyncInputProducer, AsyncInputConsumer { readonly close: Effect.Effect readonly take: Effect.Effect>> } /** * Producer-side view of `SingleProducerAsyncInput` for variance purposes. * * @since 2.0.0 * @category models */ export interface AsyncInputProducer { awaitRead(): Effect.Effect done(value: Done): Effect.Effect emit(element: Elem): Effect.Effect error(cause: Cause.Cause): Effect.Effect } /** * Consumer-side view of `SingleProducerAsyncInput` for variance purposes. * * @since 2.0.0 * @category models */ export interface AsyncInputConsumer { takeWith( onError: (cause: Cause.Cause) => A, onElement: (element: Elem) => A, onDone: (value: Done) => A ): Effect.Effect } /** * @since 2.0.0 * @category constructors */ export const make: () => Effect.Effect> = internal.make