Documentation
    Preparing search index...

    Class ReadableFlow<GValue, GArguments>

    Represents a readable flow of values that can be consumed asynchronously.

    Type Parameters

    • GValue

      The type of values emitted by the flow.

    • GArguments extends readonly unknown[] = []

      Additional arguments to pass to the flow.

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Returns true if all the values emitted by the flow satisfy the provided predicate.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • predicate: FilterFunction<GValue>

        A function to test each value from the flow. It should return a boolean.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<boolean>

      A promise that resolves to true if all the values satisfy the predicate, otherwise false.

    • Finds an item in a collection that matches the provided predicate.

      Type Parameters

      • GFilteredValue

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • predicate: FilterFunctionWithSubType<GValue, GFilteredValue>

        A function used to test each item in the collection.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<GFilteredValue | undefined>

      A promise that resolves to the first item that matches the predicate, or undefined if no match is found.

    • Finds an item in a collection that matches the provided predicate.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • predicate: FilterFunction<GValue>

        A function used to test each item in the collection.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<GValue | undefined>

      A promise that resolves to the first item that matches the predicate, or undefined if no match is found.

    • Retrieves the first value sent by the flow. If the stream is completed without sending a value, an error is thrown.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<GValue>

      A promise that resolves to the first value emitted by the flow.

      If the flow completes without sending a value.

    • Iterates over the flow and invokes the provided callback for each value.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • callback: ReadableFlowForEachFunction<GValue>

        The function to execute for each value in the flow.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<void>

      A promise that resolves once all values have been processed or rejects if an error occurs.

    • Creates a fork of the flow, allowing multiple consumers to independently read from the same source. On the first consumer, this flow opens and sends its values to this consumer and all the following, and closes when all the consumers terminate.

      The forked flow can optionally maintain its state for a specified duration even after the last consumer ends.

      Parameters

      Returns ReadableFlow<GValue, GArguments>

      A new readable flow instance that provides a shared stream of values from the original source.

    • Retrieves the last value emitted by the flow.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<GValue>

      A promise that resolves to the last emitted value.

      If the operation completes without emitting any value.

    • Transforms and filters elements of the flow based on the provided function. For each element, the function is called. If the function returns NONE, the element is filtered out; otherwise, the transformed value is included in the resulting flow.

      Type Parameters

      • GNewValue

      Parameters

      • filterFnc: MapFilterFunction<GValue, GNewValue>

        A function that takes an element of the current flow and returns either a transformed value or NONE to exclude the element.

      Returns ReadableFlow<GNewValue, GArguments>

      A new readable flow containing transformed and filtered elements.

    • Opens this Flow: it calls the provided factory function with a corresponding FlowContext.

      The provided signal is used to abort the current pending iteration.

      Parameters

      • signal: AbortSignal

        The AbortSignal that must be used to abort the current pending iteration.

      • ...args: GArguments

        The arguments to pass to the factory function.

      Returns AsyncEnumeratorObject<void, GValue, void>

      An AsyncEnumeratorObject that will be used to iterate over the flow.

    • Reduces the values produced by the flow using the provided reducer function.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • reducer: ReduceFunction<GValue, GValue>

        A function that takes the accumulated value and the current value, and returns the new accumulated value.

      • initialValue: typeof NONE

        The initial value for the reduction or a special value indicating no initial value.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<GValue>

      A promise that resolves with the final reduced value after the iteration completes.

    • Reduces the values produced by the flow using the provided reducer function.

      Type Parameters

      • GReducedValue

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • reducer: ReduceFunction<GValue, GReducedValue>

        A function that takes the accumulated value and the current value, and returns the new accumulated value.

      • initialValue: GReducedValue

        The initial value for the reduction or a special value indicating no initial value.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<GReducedValue>

      A promise that resolves with the final reduced value after the iteration completes.

    • Returns true if one of the values emitted by the flow satisfies the provided predicate.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • predicate: FilterFunction<GValue>

        A function to test each value from the flow. It should return a boolean.

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns Promise<boolean>

      A promise that resolves to true if at least one value satisfies the predicate, otherwise false.

    • Converts this readable flow into an array containing the values emitted by the flow.

      Parameters

      • signal: AbortSignal

        An AbortSignal to allow for the operation to be canceled.

      • ...args: GArguments

        Additional arguments to pass to the open method.

      Returns Promise<GValue[]>

      A promise that resolves to an array of GValue.

    • Converts this flow into a ReadableStream. This stream mimics the behavior of this flow.

      Parameters

      • ...args: GArguments

        Additional arguments to pass to the flow.

      Returns ReadableStream<GValue>

      A ReadableStream that mimics the behavior of this flow.

    • Creates a new ReadableFlow that always throws an error produced by the provided factory function.

      Type Parameters

      • GValue = never

      Parameters

      • factory: () => unknown

        A function that generates the error to be thrown.

      Returns ReadableFlow<GValue, []>

      A ReadableFlow that throws the error.