Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including p-throttle with all npm packages installed. Try it out:

var pThrottle = require("p-throttle")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

p-throttle v3.1.0

Throttle promise-returning & async functions

p-throttle Build Status

Throttle promise-returning & async functions

It also works with normal functions.

Useful for rate limiting calls to an external API, for example.


$ npm install p-throttle


Here, the trottled function is only called twice a second:

const pThrottle = require('p-throttle');

const now =;

const throttled = pThrottle(index => {
    const secDiff = (( - now) / 1000).toFixed();
    return Promise.resolve(`${index}: ${secDiff}s`);
}, 2, 1000);

for (let i = 1; i <= 6; i++) {
//=> 1: 0s
//=> 2: 0s
//=> 3: 1s
//=> 4: 1s
//=> 5: 2s
//=> 6: 2s


pThrottle(fn, limit, interval)

Returns a throttled version of fn.


Type: Function

Promise-returning/async function or a normal function.


Type: number

Maximum number of calls within an interval.


Type: number

Timespan for limit in milliseconds.


Abort pending executions. All unresolved promises are rejected with a pThrottle.AbortError error.


  • p-debounce - Debounce promise-returning & async functions
  • p-limit - Run multiple promise-returning & async functions with limited concurrency
  • p-memoize - Memoize promise-returning & async functions
  • More…


MIT © Sindre Sorhus


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free