Socket
Socket
Sign inDemoInstall

node-callback-queue

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-callback-queue

Callback queue


Version published
Weekly downloads
7
increased by600%
Maintainers
1
Install size
6.42 kB
Created
Weekly downloads
 

Readme

Source

node-callback-queue

Callback queue

Usage

    const queue = require('node-callback-queue');
    
    function onComplete(err, result){
        if(err) {
            return console.log('Error: %s', err);
        }
        console.log('Result %s', result);
    }
    
    queue
    (
        // complete callback
        onComplete,
        
        // initial callback
        function(next) {
            next(null, 'param 1', 'param 2');
        },
        
        // queued callback
        function(arg1, arg2, next){
            console.log("args %s, %s", arg1, arg2);
            // output:
            // args param 1, param 2
            next(null, arg1, arg2, true, 123);
        },
        
        // queued callback
        function(arg1, arg2, arg3, arg4, next) {
            console.log("args %s, %s, %s, %s", arg1, arg2, arg3, arg4);
            // output:
            // args param 1, param 2, true, 123
            next(null, "another arg");
        },
        
        // queued callback
        function(arg1, next){
            console.log("args %s", arg1);
            // output:
            // args another arg
            
            if(arg1 === "another arg") {
                // lets stop execution
                return next(new Error("Failed"));
            }
            
            // put args as many as next callback requires
            next(null, 1, 2, 3, 4, 5);
        },
        
        // this callback and next callbacks will be ignored
        // because previous callback send an error as first parameter
        // to "next"
        function(arg1, arg2, arg3, arg4, arg5, next){
            // if this method was executed
            // this would be final call of current queue with the result
            var result = "result";
            next(null, result);
        }
    );

Keywords

FAQs

Last updated on 25 Oct 2016

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