fluent-iterable

@fluent-iterable/async-sema

Lightweight integration between async-sema and @codibre/fluent-iterable.

This package adds a convenient runConcurrently resolving extension to both fluent and fluentAsync iterables so you can process items with a concurrency limit provided by async-sema.

Features

Installation

npm i @codibre/fluent-iterable @fluent-iterable/async-sema

Quick Examples

Important: this package registers the resolving extension when you import its src/index (packaged as dist/index.js in releases). Import it once before using the extension.

Example for a synchronous iterable (fluent):

import 'src/index'; // or import '@fluent-iterable/async-sema' after installing the package
import { fluent } from '@codibre/fluent-iterable';

const items = [1,2,3,4,5];

await fluent(items).runConcurrently({ maxConcurrency: 2 }, async (n) => {
	// do work for item n
	await doWork(n);
});

Example for an async iterable (fluentAsync):

import 'src/index';
import { fluentAsync } from '@codibre/fluent-iterable';

async function* gen() {
	for (let i = 1; i <= 5; i++) {
		await delay(10);
		yield i;
	}
}

await fluentAsync(gen()).runConcurrently({ maxConcurrency: 3 }, async (n) => {
	await doWork(n);
});

API

runConcurrently(options, cb)

Behavior notes

Testing

This package uses Jest + ts-jest. Tests live in test/unit. Run them from the package folder:

cd libs/fluent-iterable-async-sema
pnpm test

Contributing

License

ISC