Socket
Socket
Sign inDemoInstall

debounce-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    debounce-promise

Create a debounced version of a promise returning function


Version published
Weekly downloads
340K
increased by3.03%
Maintainers
1
Install size
11.3 kB
Created
Weekly downloads
 

Readme

Source

debounce-promise Build Status

NPM

Create a debounced version of a promise returning function

Install

npm i -S debounce-promise

Usage example


var debounce = require('debounce-promise')

function expensiveOperation(value) {
  return Promise.resolve(value)
}

var saveCycles = debounce(expensiveOperation, 100)

;[1,2,3,4].forEach(function(num) {
  return saveCycles('call no #' + num).then(function(value) {
    console.log(value)
  })
})

// Will only call expensiveOperation once with argument `4` and print:
//=> call no #4
//=> call no #4
//=> call no #4
//=> call no #4

With leading=true

var debounce = require('debounce-promise')

function expensiveOperation(value) {
  return Promise.resolve(value)
}

var saveCycles = debounce(expensiveOperation, 100, {leading: true})

;[1,2,3,4].forEach(function(num) {
  return saveCycles('call no #' + num).then(function(value) {
    console.log(value)
  })
})

//=> call no #1
//=> call no #1
//=> call no #1
//=> call no #1

Api

debounce(func, [wait=0], [{leading: true|false})

Returns a debounced version of func that delays invoking until after wait milliseconds. Set leading: true if you want to call func immediately and use the value from the first call for all subsequent promises.

Supports passing a function as the wait parameter, which provides a way to lazily or dynamically define a wait timeout.

Keywords

FAQs

Last updated on 24 Aug 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc