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

nue

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nue

An async control-flow library suited for the node event loop.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.5K
decreased by-0.98%
Maintainers
1
Weekly downloads
 
Created
Source

nue — An async control-flow library

nue is an async control-flow library suited for the node event loop.

Installing

$ npm install nue

Example

serial

var nue = require('nue');
var start = nue.start;
var serial = nue.serial;
var fs = require('fs');

start(serial(
  function (){
    this.data = [];
    fs.readFile('file1', this.next);
  },
  function (err, data){
    if (err) throw this.end(err);
    this.data.push(data.length);
    fs.readFile('file2', this.next);
  },
  function (err, data){
    if (err) throw this.end(err);
    this.data.push(data.length);
    this.next();
  },
  function (err) {
    if (err) throw err;
    console.log(this.data);
  }
));

serialEach

var nue = require('nue');
var start = nue.start;
var serial = nue.serial;
var serialEach = nue.serialEach;
var fs = require('fs');

start(serialEach(
  function () {
    this.data = 0;
    this.begin('file1', 'file2', 'file3');
  },
  function (name) {
    var self = this;
    fs.readFile(name, function (err, data) {
      if (err) throw this.end(err);
      self.data += data.length;
      self.next(null, self.data);
    });
  },
  function (err, data) {
    if (err) throw err;
    console.log(data);
  }
));

parallel

var nue = require('nue');
var start = nue.start;
var serial = nue.serial;
var parallel = nue.parallel;
var fs = require('fs');

start(parallel(
  function () {
    this.fork('file1', 'file2');
  },
  [
    function (name) {
      var self = this;
      fs.readFile(name, function (err, data) {
        if (err) this.err(err);
        self.join(data.length);
      });
    },
    function (path) {
      var self = this;
      fs.stat(path, function (err, stats) {
        if (err) this.err(err);
        self.join(stats.isFile());
      });
    }
  ],
  function (err, results) {
    if (err) throw err;
    console.log(results);
  }
));

parallelEach

var nue = require('nue');
var start = nue.start;
var serial = nue.serial;
var parallelEach = nue.parallelEach;
var fs = require('fs');

start(parallelEach(
  function () {
    this.begin('file1', 'file2');
  },
  function (name) {
    var self = this;
    fs.readFile(name, function (err, data) {
      if (err) this.end(err);
      self.join(data.length);
    });
  },
  function (err, results) {
    if (err) throw err;
    console.log(results);
  }
));

Keywords

FAQs

Package last updated on 01 Feb 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