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

    Function items

    • Creates a feed from a data source.

      The source contributes its items to the feed according to its shape, whatever the declared item type: an iterable or an async iterable contributes the items it yields, an existing feed among them, while any other value is contributed whole as a single item, strings and functions included. A promise is awaited when the feed is consumed, deferring retrieval from APIs, databases or any other asynchronous source until then, and contributes the value it resolves to as a single item, whatever its shape. A feed of iterable items is opened either from a batch listing them or from a promise resolving to one of them.

      The source is drawn exactly as handed over: a feed opened from a repeatable source, an array or a set among them, is consumed afresh at each pass, while one opened from a source drained by iteration, a generator object among them, runs dry after the first.

      This is the adapter a custom feed or task reaches for to obtain a feed from a generator object of its own, honouring the Feed contract without assembling one by hand; a source that is itself a feed honours it already and is handed back unchanged, so wrapping is safe to repeat and costs nothing.

      Note

      Bounded: the feed runs dry as source does, so a source that never runs dry, an endless generator among them, opens an infinite feed, 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<V> | Awaitables<V>

        The data source to open the feed from, supplied either as it is or as a promise

      Returns Feed<V>

      A feed carrying the items contributed by source

      await pipe(
      (items(new Set([1, 2, 3])))
      (toArray())
      ); // [1, 2, 3], as a batch contributes the items it yields

      await pipe(
      (items("report"))
      (toArray())
      ); // ["report"], as any other value is contributed whole

      await pipe(
      (items(Promise.resolve([1, 2, 3])))
      (toArray())
      ); // [[1, 2, 3]], as the awaited array is contributed whole in turn

      await pipe(
      (items((async function* () { yield* await fetchReport(); })()))
      (toArray())
      ); // the items of the report, drawn once and then run dry
      • flat to combine several feeds, carried in a feed of their own, into a single one
      • join to combine them as their items become available