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

vasync

Package Overview
Dependencies
Maintainers
14
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vasync

utilities for observable asynchronous control flow

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
470K
increased by3.03%
Maintainers
14
Weekly downloads
 
Created

What is vasync?

The vasync npm package provides utilities for managing asynchronous control flow in JavaScript. It is particularly useful for handling series, parallel, and queue-based asynchronous operations, making it easier to manage complex asynchronous code.

What are vasync's main functionalities?

Series

The `series` function allows you to run asynchronous tasks in series, meaning one after the other. Each task waits for the previous one to complete before starting.

const vasync = require('vasync');

vasync.series([
  function (callback) {
    setTimeout(() => {
      console.log('First task');
      callback(null, 'one');
    }, 1000);
  },
  function (callback) {
    setTimeout(() => {
      console.log('Second task');
      callback(null, 'two');
    }, 500);
  }
], function (err, results) {
  console.log('All tasks completed', results);
});

Parallel

The `parallel` function allows you to run asynchronous tasks in parallel, meaning they all start at the same time and the final callback is called when all tasks have completed.

const vasync = require('vasync');

vasync.parallel([
  function (callback) {
    setTimeout(() => {
      console.log('First task');
      callback(null, 'one');
    }, 1000);
  },
  function (callback) {
    setTimeout(() => {
      console.log('Second task');
      callback(null, 'two');
    }, 500);
  }
], function (err, results) {
  console.log('All tasks completed', results);
});

Queue

The `queue` function allows you to create a queue for processing tasks with a specified concurrency. Tasks are processed in the order they are added to the queue, but no more than the specified number of tasks will be processed at the same time.

const vasync = require('vasync');

const queue = vasync.queue(function (task, callback) {
  console.log('Processing task:', task.name);
  setTimeout(callback, 1000);
}, 2);

queue.push({name: 'task1'}, function (err) {
  console.log('Finished processing task1');
});
queue.push({name: 'task2'}, function (err) {
  console.log('Finished processing task2');
});
queue.push({name: 'task3'}, function (err) {
  console.log('Finished processing task3');
});

Other packages similar to vasync

FAQs

Package last updated on 04 Nov 2021

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