Skip to content
← Public packages

@kentcdodds/codemod-runner

Run codemods over your own saved packages: scan, dry-run with real publish checks and diffs, apply, and revert.

src/async-pool.test.ts

22 lines · 661 B · TypeScript
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { mapPool } from './async-pool.ts'

describe('mapPool', () => {
	it('returns an empty array for no items', async () => {
		assert.deepEqual(await mapPool([], 4, async (item) => item), [])
	})

	it('preserves input order with bounded concurrency', async () => {
		const seen: Array<number> = []
		const results = await mapPool([3, 1, 2], 2, async (value) => {
			seen.push(value)
			await new Promise<void>((resolve) => {
				setTimeout(resolve, 20 - value * 5)
			})
			return value * 10
		})
		assert.deepEqual(results, [30, 10, 20])
		assert.equal(seen.length, 3)
	})
})