npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fluent-iterable/async-sema

v0.1.1

Published

async-sema integration with @codibre/fluent-iterable

Readme

@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

  • Use a familiar fluent-style API to run item handlers concurrently.
  • Backed by async-sema so the semaphore is efficient and battle-tested.
  • Works with both synchronous and asynchronous iterables.

Installation

From the monorepo this package is already available as @fluent-iterable/async-sema. In normal usage install it together with @codibre/fluent-iterable and async-sema:

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.

See the projects:

  • async-sema: https://www.npmjs.com/package/async-sema
  • @codibre/fluent-iterable: https://www.npmjs.com/package/@codibre/fluent-iterable

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)

  • options: SemaOptions

    • maxConcurrency: number (required) — maximum number of concurrent executions
    • initFn?: () => unknown — forwarded to async-sema options
    • pauseFn?: () => void
    • resumeFn?: () => void
    • capacity?: number
  • cb: (item) => void | Promise

Behavior notes

  • runConcurrently registers as a resolving extension. It acquires a semaphore permit for each item and schedules the callback with setImmediate. The function resolves once it finishes acquiring and scheduling callbacks for all items; callbacks themselves run next-tick. If you rely on callbacks finishing before proceeding, wait for their completion inside the callback or use your own signaling (tests in this repo show an example).

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

  • Keep tests fast: use small delays (tens of milliseconds) when simulating async work.
  • When adding features that change how runConcurrently resolves, update tests accordingly: current implementation schedules callbacks with setImmediate, so tests must wait for completion explicitly if they assert on callback side effects.

License

ISC