mafintosh/debounceify

Tiny async debouncer

JavaScript

37

6 commits

updated Jan 12, 2024

See the code

README

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

mafintosh/debounceify

Tiny async debouncer

JavaScript

37

6 commits

updated Jan 12, 2024

See the code

README

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

Project health

Overall

2.0/10

Maintained

0/10

Code review

0/10
OpenSSF Scorecard

Latest release

1.1.0 · Jan 12, 2024

Releases this year

0

Significant stargazers

snvfk1n

59 followers · starred Jan 2021