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

async-task-throttle

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-task-throttle

A simple async task throttle.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

npm version Build Status Coverage Status

async-task-throttle

A simple async task throttle.

Install

$ yarn add async-task-throttle

Usage

Sample

import AsyncTaskThrottle from 'async-task-throttle'


function task (url) {
    return fetch(url)
}

const throttleTask = AsyncTaskThrottle.create(task, 6, 100)

// use `throttleTask` just like `task`
// but up to 6 tasks are running at the same moment
throttleTask('https://github.com/breeze2/markdown-it-all').then(value => {
    console.log(value)
}).catch(error => {
    console.error(error)
})

Interface

AsyncTaskThrottle.create

function AsyncTaskThrottle.create(
    task: T extends (...args: any[]) => Promise<any>,
    size?: number = 6,
    max: number = Infinity
): T

  • task: the async task function.
  • size: defualt 6, at the same moment, up to size tasks are runing, others are in the waiting queue.
  • max: defualt Infinity, when the length of waiting queue is greater than max, late tasks will be rejected instantly.

Keywords

async

FAQs

Package last updated on 26 Jul 2019

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