debounceify
Tiny async debouncer
Last updated 3 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install debounceify 
SYNC missed versions from official npm registry.

debounceify

Tiny async debouncer

npm install debounceify

Usage

const debounceify = require('debounceify')

const debounced = debounceify(async function () {
  console.log('Running...')
  await new Promise(resolve => setTimeout(1000, resolve))
})

const a = debounced() // triggers the about function
const b = debounced()
const c = debounced()
const d = debounced() // these last 3 wait for the first one to finish
                      // then trigger one more.

await a
await b
await c
await d

API

fn = debounceify(asyncFunction)

Debounces the asyncFunction so that

  1. No parallel executions of asyncFunction will happen
  2. Debounces the stack, so if 10 calls happen while asyncFunction is running only one more will be triggered when it finishes.
  3. Forwards errors and return values.

debounceify.running

The active running job, null if none.

License

MIT

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

3 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Total 8
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 2
Last Month 1
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE