Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chunk-async

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chunk-async

Helps to chunk data and resolve async work on large datasets

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

chunk-async

Helps to chunk data and resolve async work to large datasets

NPM version

Features

  • Chunk array[....] of data into array[[..]‚[..]]
  • Resolve async work done on items
  • Chunk and resolve async work, chunk by chunk

Install

npm install chunk-async

Usage

chunk()

Chunks array[....] of data into array[[..]‚[..]]

const { chunk, chunkAndResolve, resolve } = require('async-work');

let items = [1,2,3,4,5,6,7,8,9,10];
let chunkSize = 2;
let chunks = chunk(items, chunkSize);
console.log(chunks)
//  [ [1,2], [3,4], [5,6], [7,8], [9,10] ]

resolve()

Resolves async work done on items

const { resolve } = require('async-work');
const axios = require('axios').default;

let items = [1,2,3,4,5,6,7,8,9,10];
//  Example async work
let asyncWork = async (item)=>{
  let url = `https://jsonplaceholder.typicode.com/posts/${item}`;
  let result = await axios.get(url);
  return result.data
};

resolve(items, asyncWork).then(res=>{
  console.log(res)
  //  Items from  api
});

chunkAndResolve()

Chunk and resolve async work, chunk by chunk

const { chunkAndResolve } = require('async-work');
const axios = require('axios').default;

let persons = [{id: 1, name: 'John'}, ... {id:10000, name: 'Mark'}];  //  Large dataset
let chunkSize = 100;
let showDebug = true;
let asyncWork = async(person)=>{
  let result = await axios.get(`http://yourApi.com/getFullnameById/${person.id}`);
  person.fullname = result.data;
  return person;
};

chunkAndResolve(persons, chunkSize, asyncWork, showDebug).then(result=>{
  console.log(result)
  //  [ {id:1, name: 'John', fullname: 'John Doe'}, ...]
})

Keywords

FAQs

Package last updated on 13 Jan 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc