Socket
Socket
Sign inDemoInstall

zig

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zig

Simple, but naughty, control flow for Node.js.


Version published
Weekly downloads
49
decreased by-48.42%
Maintainers
1
Weekly downloads
 
Created
Source

Zig - Simple, but naughty, control flow for Node.js

Why have an if statement when you can have an if function?

A special case solution for callback hell that focuses on developer ease-of-use. Executes your functions in series or parallel, tracks errors and results, and provides conditionals.

Build Status

NPM NPM

If you're using this plugin module, feel free to contact me on twitter if you have any questions! :) @rjrodger

Current Version: 0.0.2

Tested on: Node 0.10.31

Install

npm install zig

Quick Example

Here's the classic Mongo example. Look ma, no callbacks! Nice and linear down the page.

var zig = require('..') 

var MongoClient = require('mongodb').MongoClient
var format = require('util').format;

var db,collection

zig({trace:false})
  .wait(function(data,done){
    MongoClient.connect('mongodb://127.0.0.1:27017/test', done)
  })
  .step(function(data){
    db = data
    return collection = db.collection('test_insert')
  })
  .wait(function(data,done){
    collection.insert({a:2},done)
  })
  .wait(function(data,done){
    collection.count(done)
  })
  .step(function(count){
    console.log(format("count = %s", count));
    return true;
  })
  .wait(function(data,done){
    collection.find().toArray(done)
  })
  .end(function(err,docs){
    if( err ) return console.log(err);
    console.dir(docs)
    db.close()
  })

And the original, callback hell:

  var MongoClient = require('mongodb').MongoClient
  , format = require('util').format;

  MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
    if(err) throw err;

    var collection = db.collection('test_insert');
    collection.insert({a:2}, function(err, docs) {

      collection.count(function(err, count) {
        console.log(format("count = %s", count));
      });

      collection.find().toArray(function(err, results) {
        console.dir(results);
        db.close();
      });
    });
  })

Testing

npm test

Releases

  • 0.0.2: steps can exit
  • 0.0.1: first working version

FAQs

Package last updated on 13 Oct 2014

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