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

jobs-queues

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jobs-queues

A sequential jobs manager in Express.js style

  • 0.9.3
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

jobs-queues

Plugin that gives you sequential queues for your jobs as Array-like Objects in Express style

Installation

npm i jobs-queues

Test

npm test

Usage

const jobsQueues = require( 'jobs-queues' );
const queue = jobsQueues();
queue.push(                                             //Push a job list
    ( finish ) => {
                                                        // Any job
        setTimeout( () => {
            console.log( 'First job finished' );
            finish( true, 'Hello world!' )              // At the end call finish() with your results
        }, 2500 );
    },

    ( finish, empty, ...results ) => {
                                                        // Another job
        if ( results[0] ) {
            finish( results[1] );                       // Call finish() with your result
        } else {                                        // OR
            empty();                                    // Stop this job list
        }
        console.log( 'Second job finished' );
    },
    
    async ( finish, empty, result ) => {
                                                        // Another job
        await new Promise( r => setTimeout( r, 500 ) );
        console.log( result );
        finish();                                       // Call finish()
    }
);
queue.push(
    ( finish ) => {
        console.log( 'Another job list' );
        finish();
    }
);

queue.onError( ( err, refs ) => {
    console.log( { err, refs } );
} );

Constructor

jobsQueues( started = true [, ...jobList: Function] );
Parameters
  • started Default true - Set to false if you want to start your jobs later
  • jobList Optional - Any function that accepts three parameters:
    • finish Required - A callback you have to call at the end of every job. It accepts ...results and pass them to the next job in the same job list
    • empty Optional - A callback you have to call to stop the jobs in the same job list
    • ...results Optional - Any result yo have passed in the finish() of the previous one job in the same job list
Return

A JobsQueues instance that extends Array

Methods

push

queue.push( ...jobList );
Return

The index of the job list as Integer

start

queue.start();

onError

queue.onError( callback );
Parameters
  • callback Required - A function that accepts error and referements of the interrupted job list index and job index (in the order you've pushed them)

Note

A job list is not directly related with errors of another. It runs in anyway when the previous one exits.

Keywords

FAQs

Package last updated on 12 Nov 2022

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