crnt - v0.0.31
    Preparing search index...

    Function newStream

    • Creates a Stream from a synchronous Iterable or AsyncIterable with optional configuration.

      This function wraps both synchronous iterables (arrays, sets, etc.) and asynchronous iterables (async generators, etc.) and converts them to streams for concurrent processing.

      Type Parameters

      • T

        The type of items in the iterable

      Parameters

      • iterable: Iterable<T, any, any> | AsyncIterable<T, any, any>

        Any Iterable or AsyncIterable to wrap as a Stream

      • Optionalconfig: StreamConfig

        Optional default configuration for all operations on this stream

      Returns Stream<T>

      A new Stream instance

      // From an array
      const numbers = [1, 2, 3, 4, 5];
      const stream = Stream(numbers, {
      concurrency: 3,
      batchSize: 2
      });

      // From a Set
      const uniqueItems = new Set(['a', 'b', 'c']);
      const results = await Stream(uniqueItems)
      .map(async item => item.toUpperCase());

      // From an async generator
      async function* generateData() {
      for (let i = 0; i < 100; i++) {
      yield i;
      }
      }
      const asyncStream = Stream(generateData());