Skip to content

v4.0.0

Compare
Choose a tag to compare
@sindresorhus sindresorhus released this 19 Jan 09:14

Breaking

  • Require Node.js 10 (#22) 5cb0a4e
  • Currify function and move arguments to an optons-object (#22) 5cb0a4e
 const pThrottle = require('p-throttle');

 const now = Date.now();

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

 for (let i = 1; i <= 6; i++) {
 	throttled(i).then(console.log);
 }

This has the benefit that it allows reusing the throttled instance. See: #16

v3.1.0...v4.0.0