0.2.0 • Published 2 years ago

@scholten.dev/concurrency v0.2.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Concurrency

Ratelimiting

This service makes sure a limited amount of async calls will be running at the same time.

// Run only 2 requests at the same time
const rateLimit = new RateLimit({ concurrent: 2 });

await Promise.all([0,1,2,3,4,5,6,7,8,9].map(async () => {
    return rateLimit.enqueue<Response>(async () => {
        const request = await fetch('https://example.com');
        return request.text();
    });
});

Sleep

// Pause the current thread with 1 second
await sleep (1000);