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

conseq

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conseq

Small, simple callback chaining for async methods

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Conseq

node-conseq is a small, simple library for handling the nesting explosion. It is heavily inspired by node-seq.

node-conseq can handle node-style EventEmitter callbacks as well as error-as-first-argument callbacks.

Examples

var Seq = require('conseq')
var http = require('http')

Seq()
  .seq(function () {
    http.get({host: 'www.google.com', path: '/index.html'}, this.next)
      .on('error', this.error)
  })
  .seq(function (res) {
    if (res.statusCode == 200) {
      res.on('data', this.next)
    } else {
      this.error({message: 'Error ' + res.statusCode})
    }
  })
  .seq(function (data) {
    console.log("Got data: " + data)
  })
  .catch(function (err) {
    console.log("there was an error! " + JSON.stringify(err))
  })

Use this.next as a callback to proceed to the next function in the chain. Use this.error as a callback to be called in an error condition. this.combined is a convenience, meaning:

function (err, ...) {
  if (err) this.error(err)
  else this.next(...)
}

Parallel function callbacks

Seq()
  .seq(function () {
    fs.stat('/etc/passwd', this.parcombined)
    fs.stat(process.env['HOME'], this.parcombined)
  })
  .seq(function (results) {
    console.log('/etc/passwd', results[0].isFile() ? "is" : "is not", "a file")
    console.log(process.env['HOME'], results[1].isDirectory() ? "is" : "is not", "a directory")
  })

parcombined works like combined does for single action steps. par is the parallel equivalent of next, and parerror for error.

Installing

Install with npm install conseq. If you want to run the tests, you'll need to install zap.

FAQs

Package last updated on 29 Jun 2012

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