npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-block

v0.1.6

Published

An async control-flow library. Easily error handling.

Downloads

6

Readme

node-block

An async control-flow library for Node.js.
Easily parallel execution and error handling.

Installation

$ npm install node-block

Example

var fs = require('fs');
var block = require('node-block').block;

block(
  function() {
    fs.readFile('/path/to/file1', 'utf8', this.async('d1'));
    fs.readFile('/path/to/file2', 'utf8', this.async('d2'));
  },
  function() {
    var str = this.data.d1 + this.data.d2;
    console.log(str);
  }
)();

Error handling

Function name is cat and fin.

var fs = require('fs');
var block = require('node-block').block;

block(
  function() {
    fs.readFile('/path/to/file1', 'utf8', this.async('d1'));
    fs.readFile('/path/to/file2', 'utf8', this.async('d2'));
  },
  function() {
    this.data.d3 = this.data.d1 + this.data.d2;
  },
  function cat(e) {       // catch
    console.log(e);
    throw e;
  },
  function fin() {        // finally
    console.log('fin');   // always run
  }
)();

Jump to end

call this.end() with return.

var fs = require('fs');
var block = require('node-block').block;

block(
  function() {
    if (true) {
      return this.end();  // called with return
    }
  },
  function() {
    // not run here.
  },
  function cat(e) {       // catch
    // when errorless, not run here.
  },
  function fin() {        // finally
    console.log('fin');   // always run
  }
)();

Callback

sample() is called after fin().

var fs = require('fs');
var block = require('node-block').block;

block(
  function() {
    fs.readFile('/path/to/file1', 'utf8', this.async('d1'));
  },
  function fin() {
    console.log('fin');
  }
)(sample);

function sample(err){
  if (err) throw err;
  console.log(this.data.d1);
}

Nesting

var fs = require('fs');
var block = require('node-block').block;

block(
  function() {
    fs.readFile('/path/to/file1', 'utf8', this.async('d1'));
    fs.readFile('/path/to/file2', 'utf8', this.async('d2'));
  },
  function() {
    fs.readFile('/path/to/file3', 'utf8', this.async('d3'));
    block(
      function() {
        fs.readFile('/path/to/file4', 'utf8', this.async('e1'));
        fs.readFile('/path/to/file5', 'utf8', this.async('e2'));
      },
      function() {
        fs.readFile('/path/to/file6', 'utf8', this.async('e3'));
      }
    )(this.async('d4'));
  },
  function() {
    var str = this.data.d1 + this.data.d2 + this.data.d3 +
      this.data.d4.e1 + this.data.d4.e2 + this.data.d4.e3;
    console.log(str);
  }
)();

setTimeout

var block = require('node-block').block;

block(
  function() {
    var cb1 = this.async('d1');
    setTimeout(function() {
      try {
        cb1(null, 'abc');
      } catch (e) {
        cb1(e);
      }
    }, 1000);
  },
  function() {
    var str = this.data.d1;
    console.log(str);   // abc
  }
)();

License

The MIT License