The type of items in the iterable
Any Iterable or AsyncIterable to wrap as a Stream
Optional
config: StreamConfigOptional default configuration for all operations on this stream
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());
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.