This package has been deprecated

Author message:

deprecated in favor of Wraperizer.throttleAsync

throttled-async

3.0.4-d • Public • Published

Deprecated in favor to Wraperizer.throttleAsync. No longer support.

Throttled

Create wrapper for a function that returns a promise. Uses to throttle frequent or repeated calls.

Parameters

  • fn function function that returns a promise
  • config object? config object
    • config.stay function function that checks is fn invokes is necessary (optional, default function(){returnfalse})
    • config.logs any? determines is internal logs needed

Examples

const Throttled = require('throttled-async');
 
const config = {}
 
const fn = (params) => new Promise((resolve, reject) => setTimeout(() => resolve(params), 100));
 
let throttled = new Throttled(fn, config);
let params = {};
const r1 = throttled.run(params); // will invoke `fn` and return Promise
const r2 = throttled.run(params); // will return old Promise
 
setTimeout(() => {
    const r3 = throttled.run(params); // will invoke `fn` and return new Promise
}, 300)

run

invokes fn and returns resulting promise

Parameters

  • params Object arguments for fn call

  • Throws Error throws an error if result returned fn is not a Promise

Returns Promise

stay

getter - returns current stay function

Returns function

stay

setter - set new value of stay function

Parameters

  • value function

  • Throws Error throws an error if value is not a function

Package Sidebar

Install

npm i throttled-async

Weekly Downloads

180

Version

3.0.4-d

License

ISC

Unpacked Size

8.71 kB

Total Files

9

Last publish

Collaborators

  • a.chepugov