New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fail-safe-queue

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fail-safe-queue

Node.js callbacks queue with rollback capabilities on fail.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Fail Safe Queue

It's a very simple Queue of functions. But also let's you define, for each one, a rollback in case something goes wrong later on the queue stack calling.

Heavily inspired by caolan/async.

Installation

npm install fail-safe-queue --save

Quick Examples

Success example:

var queue = require('fail-safe-queue')

queue([
  {
    up: function(next){
      console.log('+ up! 1')
      next(null, 1)
    },
    down: function(prev){
      console.log('- down! 1')
      prev()
    }
  },
  function(next){
    console.log('+ up! 2')
    next(null, 2)
  },
  {
    up: function(next){
      console.log('+ up! 3')
      next('3 con error', 3)
    },
    down: function(prev){
      console.log('- down! 3')
      prev()
    }
  }
], function(err, upResults, downResults){
  console.log('err', err)
  console.log('upResults', upResults)
})

Will echo:

  + up! 1
  + up! 2
  + up! 3
  err null
  results [ [ 1 ], [ 2 ], [ 3 ] ]

Fail example:

var queue = require('fail-safe-queue')

queue([
  {
    up: function(next){
      console.log('+ up! 1')
      next(null, 1)
    },
    down: function(prev){
      console.log('- down! 1')
      prev()
    }
  },
  {
    up: function(next){
      console.log('+ up! 2')
      next('This method triggered an error :S', 2)
    },
    down: function(prev){
      console.log('- down! 2')
      prev()
    }
  },
  {
    up: function(next){
      console.log('+ up! 3')
      next(null, 3)
    },
    down: function(prev){
      console.log('- down! 3')
      prev()
    }
  }
], function(err, upResults){
  console.log('err', err)
  console.log('upResults', upResults)
})

Will echo:

  + up! 1
  + up! 2
  - down! 1
  err This method triggered an error :S
  results [ [ 1 ] ]

API

queue(tasks, [callback])

Arguments

  • tasks - It's an array of tasks. Each task could be a simple function to be called in order or an object with two functions, up: [Function(next)] and down: [Function(prev)].
  • callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to the task callbacks.

Keywords

FAQs

Package last updated on 27 Feb 2015

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