debounce-with-result
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

debounce-with-result

NPM version npm
A debounce variation that returns a result as a Promise

Installation

npm install debounce-with-result

Usage

Just like the debounce that we all know and love, except that this one returns a Promise.

function doSomething() {
  console.log('doSomething was called');
}
 
let doSomethingDebounced = debounceWithResult(doSomething, 500);
// `doSomething()` runs only once
doSomethingDebounced().then(() => { console.log('doSomething resolved'); });
doSomethingDebounced().then(() => { console.log('doSomething resolved'); });
doSomethingDebounced().then(() => { console.log('doSomething resolved'); });
 
 
function getSomething() {
    console.log('getSomething was called');
    return 5;
}
 
let getSomethingDebounced = debounceWithResult(getSomething, 500);
// `getSomething()` runs only once and three logs appear
getSomethingDebounced().then((result) => { console.log('getSomething resolved ' + result); });
getSomethingDebounced().then((result) => { console.log('getSomething resolved ' + result); });
getSomethingDebounced().then((result) => { console.log('getSomething resolved ' + result); });
 

Examples

Jsbin example

Readme

Keywords

Package Sidebar

Install

npm i debounce-with-result

Weekly Downloads

16

Version

1.0.1

License

none

Last publish

Collaborators

  • thgreasi