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

    Function peek

    • Creates a task observing the feed without altering it.

      Every item is handed to the consumer before being emitted unchanged, making the feed observable at any point of a pipe for tracing, logging or metering purposes.

      Note

      • Incremental: items are emitted as they are drawn, so the reported feed runs dry as the feed drawn from does.
      • Streaming: items are observed one at a time, none retained.
      • Stateless: every item is observed on its own, so the outcome is unaffected by how the feed is split across nested feeds or runs.

      Type Parameters

      • V

        The type of items in the feed

      Parameters

      • consumer: (item: NoInfer<V>) => unknown

        The function observing each item; a returned promise is awaited before the item moves on, so asynchronous side effects hold the feed back until they complete

      Returns Task<V>

      A task yielding the items of the feed unchanged

      await pipe(
      (items([1, 2, 3]))
      (peek(n => console.log(n)))
      (toArray())
      ); // logs 1, 2, 3; [1, 2, 3]