New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by7.24%
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

var flow = require('nue').flow;
var fs = require('fs');

var myFlow = flow(
  function (file1, file2) {
    fs.readFile(file1, 'utf-8', this.async());
    fs.readFile(file2, 'utf-8', this.async());
  },
  function (data1, data2) {
    this.next(data1 + data2);
  },
  function (data) {
    console.log(data);
    console.log('done');
    this.next();
  }
);

myFlow('file1', 'file2');

API

### flow([Function tasks...]) -> Function

Return a function which represents the control-flow.

Arguments

  • tasks: Optional. Tasks which are executed in series.

Context

this context of the each task has following properties.

  • next: Function. A function to execute a next task.
  • async: Function. A function to accept parameters for a next task and return a callback.
  • end: Function. A function to execute a last task to end a control-flow. The first parameter is an error object.
  • queue: Function. A function to create a serial queue object.
  • parallelQueue: Function. A function to create a parallel queue object.
  • data: Object : A object to share arbitrary data among functions in a control-flow.

In addition to the above ones, the context of the last task has a following property.

  • err: Object. An object represents an error which passed from the end function.

Data Sharing Among Functions

var flow = require('nue').flow;
var fs = require('fs');

var myFlow = flow(
  function (file1, file2) {
    this.data.file1 = file1;
    this.data.file2 = file2;
    fs.readFile(file1, 'utf-8', this.async());
    fs.readFile(file2, 'utf-8', this.async());
  },
  function (data1, data2) {
    this.next(data1 + data2);
  },
  function (data) {
    console.log(data);
    console.log(this.data.file1 ' and ' + this.data.file2 ' are concatenated.');
    this.next();
  }
);

myFlow('file1', 'file2');

Error Handling

var flow = require('nue').flow;
var fs = require('fs');

var myFlow = flow(
  function (file1, file2) {
    fs.readFile(file1, 'utf-8', this.async());
    fs.readFile(file2, 'utf-8', this.async());
  },
  function (data1, data2) {
    this.next(data1 + data2);
  },
  function (data) {
    if (this.err) {
      // handle error
      ...
      // indicate error handling completion
      this.err = null;
    } else {
      console.log(data);
    }
    console.log('done');
    this.next();
  }
);

myFlow('file1', 'file2');

Keywords

FAQs

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