Socket
Socket
Sign inDemoInstall

@dnpr/task-manager

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dnpr/task-manager

Run JavaScript functions concurrently with control.


Version published
Weekly downloads
2K
decreased by-2.2%
Maintainers
1
Install size
13.9 kB
Created
Weekly downloads
 

Readme

Source

task-manager

A simple JavaScript task scheduler that manages execution of synchronous or asynchronous tasks.

Installation

npm install @dnpr/task-manager

Usage

  • (Recommended) To use v2, see test/TaskManager2.spec.js.
  • To use v1, see test/TaskManager.spec.js.

Background

Since this scheduler still executes tasks with single thread, it cannot make synchronous, computation intensive tasks faster. However, if the tasks are asynchronous, such as web requests or file-system reads / writes, which are more I/O bounded, they have chances to benefit from the concurrency under single thread.

The original reason I write this is for web crawling. I found making requests one by one was too slow, so I wonder if I can make it run in parallel. It turned out that I had to add quite much code to achieve the goal. Therefore, I decided to write a library to make reusing easier.

With this library I just need to prepare 3 things:

  1. A tasks array, where each task is an object containing a URL and some metadata.
  2. A function that execute a task. For instance, making a request to the URL and save its response.
  3. A config object describing how to schedule the tasks. It may include the number of tasks that should run in parallel, the delay between two tasks, and the variation of delay to add some "randomness" to the traffic shape.

Then, let it run and wait !

FAQs

Last updated on 18 Jun 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