New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@shokai/async-throttle

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shokai/async-throttle

make async/promise function execute only one at a time.

latest
Source
npmnpm
Version
0.2.3
Version published
Maintainers
1
Created
Source

async-throttle

make async/promise function execute only one at a time.

  • https://github.com/shokai/async-throttle
  • https://npmjs.com/package/@shokai/async-throttle

Usage

throttle

const asyncThrottle = require('@shokai/async-throttle')

const delay = msec => new Promise(resolve => setTimeout(resolve, msec))

async function countUp (n = 0) {
  for (let i = 0; i < 5; i++) {
    console.log(n + i)
    await delay(100)
  }
}
const throttledCountUp = asyncThrottle(countUp)

throttledCountUp(0) // run
throttledCountUp(10) // skip this
await throttledCountUp(20) // skip this, but wait for "throttledCountUp(0)" to finish

throttledCountUp(30) // run this

result

0
1
2
3
4
30
31
32
33
34

trailing

When the function being executed is finished, it is executed only once at the last.

const throttledCountUp = asyncThrottle(countUp, {trailing: true})

throttledCountUp(0) // run
throttledCountUp(10) // skip
throttledCountUp(20) // skip
throttledCountUp(30) // run, but wait for "throttledCountUp(0)" to finish

result

0
1
2
3
4
30
31
32
33
34

Keywords

async

FAQs

Package last updated on 04 Feb 2023

Did you know?

Socket

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