PHP 8.2.30
Preview: index.js Size: 1.02 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/pkg-dir/node_modules/p-locate/index.js

'use strict';
const pLimit = require('p-limit');

class EndError extends Error {
	constructor(value) {
		super();
		this.value = value;
	}
}

// The input can also be a promise, so we `Promise.resolve()` it
const testElement = (el, tester) => Promise.resolve(el).then(tester);

// The input can also be a promise, so we `Promise.all()` them both
const finder = el => Promise.all(el).then(val => val[1] === true && Promise.reject(new EndError(val[0])));

module.exports = (iterable, tester, opts) => {
	opts = Object.assign({
		concurrency: Infinity,
		preserveOrder: true
	}, opts);

	const limit = pLimit(opts.concurrency);

	// Start all the promises concurrently with optional limit
	const items = [...iterable].map(el => [el, limit(testElement, el, tester)]);

	// Check the promises either serially or concurrently
	const checkLimit = pLimit(opts.preserveOrder ? 1 : Infinity);

	return Promise.all(items.map(el => checkLimit(finder, el)))
		.then(() => {})
		.catch(err => err instanceof EndError ? err.value : Promise.reject(err));
};

Directory Contents

Dirs: 0 × Files: 4

Name Size Perms Modified Actions
1.02 KB lrw-r--r-- 2026-02-28 00:26:42
Edit Download
1.08 KB lrw-r--r-- 2026-02-28 00:26:52
Edit Download
823 B lrw-r--r-- 2026-02-28 00:26:32
Edit Download
2.03 KB lrw-r--r-- 2026-02-28 00:27:04
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).