UNPKG

opnet

Version:

The perfect library for building Bitcoin-based applications.

17 lines (16 loc) 475 B
import pLimit from 'p-limit'; import { Agent, fetch as undiciFetch } from 'undici'; export function getFetcher(configs) { const agent = new Agent(configs); const limit = pLimit(500); async function limitedFetch(input, init) { return limit(() => undiciFetch(input, { ...init, dispatcher: agent })); } return { fetch: limitedFetch, close: async () => { await agent.close(); }, }; } export default getFetcher;