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

lcherone-task-queue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lcherone-task-queue

A simple wrapper for fastq

  • 1.0.1
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

lcherone-task-queue

This library provides a simple task queue for handling asynchronous tasks. Which uses a basic interval timer and fastq.

Installation

To install lcherone-task-queue, run the following command:

npm i lcherone-task-queue

Usage

To use lcherone-task-queue, follow these steps:

  1. Import the lcherone-task-queue library:
const Tasks = require('lcherone-task-queue')
  1. Create a new instance of the Tasks class:
const tasks = new Tasks()
  1. Add a new task queue to the Tasks instance:
tasks.add(
  // Name of the task queue
  'email',
  {
    // The finder function should return a list of jobs as a Promise
    finder: () => {
      return Promise.resolve(Array.from({ length: 10000 }, (_, i) => i + 1))
    },

    // The job worker, gets passed the single item should callback
    worker: function (input, cb) {
      // Log the input to the console
      console.log('worker', input)
      // Call the callback with a null error and the result of the job (in this case, the input multiplied by 2)
      cb(null, input * 2)
    },

    // The success handler, handles if the single job item completed
    onSuccess: (input, result) => {
      // Log the result and input to the console
      console.log('onSuccess', result, input)
    },

    // The error handler, handles if the single job item failed
    onError: (input, err) => {
      // Log the error and input to the console
      console.log('onError', err, input)
    },

    // The interval in ms on when to fire the job finder
    interval: 1000
  }
)
  1. Run the task queue:
tasks.run()

Options

  • finder: A function that returns a Promise resolving to a list of jobs.
  • worker: A function that processes a single job item. It should accept two arguments: input (the job item) and cb (a callback function). The callback should be called with two arguments: err (an error if one occurred) and result (the result of the job).
  • onSuccess: A function that is called when a job item is successfully processed. It should accept two arguments: input (the job item) and result (the result of the job).
  • onError: A function that is called when an error occurs while processing a job item. It should accept two arguments: input (the job item) and err (the error).
  • interval: The interval in milliseconds at which to run the finder function.

FAQs

Package last updated on 07 Jan 2023

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