Код: Выделить всё
import NeoIp from './NeoIp.js';
import { v4 as uuidv4 } from 'uuid';
import pLimit from 'p-limit'; //Attempted this, and the two at the bottom.
//import * as pLimitModule from 'p-limit';
//const pLimit = pLimitModule.default || pLimitModule;
class NeoIpList {
// [...] Abbreviated
async arinSearchAll() {
// Arin has a daily api limit of 100,000
// Maximum of 10 calls per second.
const alreadySearched = new Set(); // More appropriate than Map here
// --------------------------
//#region pLimit, Concurrency
// --------------------------
try {
const alreadySearched = new Set(); // More appropriate than Map here
const limit = pLimit(5); // Limit to 5 concurrent requests
const tasks = this.list
.map((singleIp) => {
if (!alreadySearched.has(singleIp)) {
alreadySearched.add(singleIp);
return limit(() => singleIp.arinSearchSingle());
}
return null;
})
.filter(Boolean); // Remove nulls from already-searched IPs
const results = await Promise.all(tasks);
return results;
// [...] No longer relevant.
< /code>
TypeError: pLimit is not a function
< /code>
Aside from checking the different, commented-out approaches above, I've also gone ahead and verified that p-limit is, in fact, downloaded with npm show p-limitnpm show p-limit
p-limit@6.2.0 | MIT | deps: 1 | versions: 19
Run multiple promise-returning & async functions with limited concurrency
https://github.com/sindresorhus/p-limit#readme
keywords: promise, limit, limited, concurrency, throttle, throat, rate, batch, ratelimit, task, queue, async, await, promises, bluebird
dist
.tarball: https://registry.npmjs.org/p-limit/-/p-limit-6.2.0.tgz
.shasum: c254d22ba6aeef441a3564c5e6c2f2da59268a0f
.integrity: sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==
.unpackedSize: 10.3 kB
dependencies:
yocto-queue: ^1.1.1
maintainers:
- sindresorhus
dist-tags:
latest: 6.2.0
published 4 months ago by sindresorhus
< /code>
Could use a few more ideas on troubleshooting this.
Подробнее здесь: https://stackoverflow.com/questions/795 ... a-function
Мобильная версия