@metreeca/flow - v0.10.0
    Preparing search index...

    Function inlet

    • Creates a feed over an external source of items, drawn one at a time on demand.

      Random generators, queues, cursors, event subscriptions and any other source handing over one value per call enter a pipe through this feed, called again once the value it reported last has been consumed. Every value is contributed as a single item, whatever its shape and without being expanded further, so arrays and iterables are carried whole and falsy values, undefined included, are preserved; a promised value is awaited before being contributed.

      The feed ends where the source reports done in place of a value, the marker itself withheld from the items: a source knowing when it is exhausted bounds the feed at the origin, without a wrapper generator of its own.

      The optional signal bounds the feed from the outside, tested before each call: an aborted signal ends the feed as an exhausted source does, so a deadline or a withdrawn request leaves the items already contributed to the pipe that consumes them. A cancellation asked for while a promised value is in flight takes effect once that value has been contributed, and signal.aborted tells a partial outcome from a complete one.

      Warning

      Infinite: the feed runs on unless source reports done or signal is aborted, so a source that never ends it leaves it to be bounded downstream, by a task such as take or by a sink deciding its outcome early.

      Type Parameters

      • V

        The type of items contributed to the feed

      Parameters

      • source: () => Awaitable<typeof done | V>

        The function called repeatedly to produce the next value, reported either as it is or as a promise, or done to end the feed

      • Optionalsignal: AbortSignal

        The optional signal bounding the feed from the outside; if omitted, the source alone decides how far the feed goes

      Returns Feed<V>

      A feed yielding the values reported by successive source calls, until either the source reports done or signal is aborted

      await pipe(
      (inlet(() => Math.random()))
      (take(3))
      (toArray())
      ); // [0.123, 0.456, 0.789]

      await pipe(
      (inlet(() => queue.size ? queue.poll() : done))
      (toArray())
      ); // every value queued, until the queue runs dry

      await pipe(
      (inlet(() => cursor.next(), AbortSignal.timeout(1_000)))
      (toArray())
      ); // every value the cursor reports within the deadline
      • items to open a feed from a source contributing its items according to its shape
      • AbortSignal