"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_promises_options = require('../promises/options.js');
const require_promises_retry = require('../promises/retry.js');
let src_external_streaming_iterables = require("../external/streaming-iterables");

//#region src/streams/parallel.ts
/**
* @file Parallel iteration helpers — `parallelMap()` and the fire-and-forget
*   `parallelEach()`. Built on top of `streaming-iterables.parallelMap` with
*   the project's `pRetry` wrapper applied per item.
*/
/**
* Execute a function for each item in an iterable in parallel.
*
* @example
*   ;```typescript
*   const urls = ['https://a.io', 'https://b.io']
*   await parallelEach(
*     urls,
*     async url => {
*       await fetch(url)
*     },
*     { concurrency: 4 },
*   )
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
async function parallelEach(iterable, func, options) {
	for await (const _ of /* @__PURE__ */ parallelMap(iterable, func, options));
}
/**
* Map over an iterable in parallel with concurrency control.
*
* @example
*   ;```typescript
*   const ids = [1, 2, 3]
*   for await (const result of parallelMap(
*     ids,
*     async id => {
*       return await fetchData(id)
*     },
*     4,
*   )) {
*     console.log(result)
*   }
*   ```
*/
/*@__NO_SIDE_EFFECTS__*/
function parallelMap(iterable, func, options) {
	const opts = /* @__PURE__ */ require_promises_options.normalizeIterationOptions(options);
	return (0, src_external_streaming_iterables.parallelMap)(opts.concurrency, async (item) => {
		return await /* @__PURE__ */ require_promises_retry.pRetry((...args) => func(args[0]), {
			...opts.retries,
			args: [item]
		});
	}, iterable);
}

//#endregion
exports.parallelEach = parallelEach;
exports.parallelMap = parallelMap;