Socket
Socket
Sign inDemoInstall

callback-chunk

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    callback-chunk

A simple JS library to chunk an array of callbacks asynchronously


Version published
Weekly downloads
7
increased by75%
Maintainers
1
Install size
4.01 kB
Created
Weekly downloads
 

Readme

Source

callback-chunk

A simple JS library to chunk an array of callbacks asynchronously

Installation

npm:

npm install callback-chunk --save

Yarn:

yarn add callback-chunk

Usage

Import the module:

const chunk = require('callback-chunk');

Call the function with your Array of callbacks:

const ticks = 50; // Number of calls at once
const callbacks = [
    () => { /* your code here */ },
    // ...
];

await chunk(
    callbacks, // The callbacks Array (Array of functions)
    ticks, // The number of functions called at once
    console.log // Custom logger, defaults to null
);

Example

const chunk = require('callback-chunk');

async function main() {
    const callbacks = new Array(30)
        .fill(
            () => new Promise(
                resolve => setTimeout(() => resolve(), Math.floor(Math.random() * 5000))
            )
        );
    
    console.log('Started chunking...');

    await chunk(callbacks, 10, console.log);

    console.log('Finished chunking');
}

main().catch(console.error);

Keywords

FAQs

Last updated on 21 Mar 2022

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc