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 - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

CHANGELOG.md

6

examples/argsPassing.js

@@ -9,5 +9,5 @@ var flow = require('../index').flow;

},
function concat(file1, data1, file2, data2) {
console.log(file1 + ' and ' + file2 + ' have been read.');
this.next(data1 + data2);
function concat(data1, data2) {
console.log(data1[0] + ' and ' + data2[0] + ' have been read.');
this.next(data1[1] + data2[1]);
},

@@ -14,0 +14,0 @@ function end(data) {

@@ -9,3 +9,3 @@ var flow = require('../index').flow;

fs.readFile(file, 'utf8', this.async());
}.bind(this));
}, this);
},

@@ -12,0 +12,0 @@ function concat(files) {

@@ -6,4 +6,4 @@ var flow = require('../index').flow;

function readFiles(file1, file2) {
if (!file1) throw new Error('file1 is illegal.');
if (!file2) throw new Error('file2 is illegal.');
if (!file1) this.endWith(new Error('file1 is illegal.'));
if (!file2) this.endWith(new Error('file2 is illegal.'));
fs.readFile(file1, 'utf8', this.async());

@@ -10,0 +10,0 @@ fs.readFile(file2, 'utf8', this.async());

@@ -19,2 +19,3 @@ var flow = require('../index').flow;

);
myFlow('file1', 'file2');

@@ -31,3 +31,2 @@ var flow = require('../index').flow;

}
console.log(this.stepName);
console.log('done');

@@ -34,0 +33,0 @@ this.next();

@@ -20,3 +20,3 @@ var flow = require('../../index').flow;

describe('concatFiles flow', function () {
describe('flow `concatFiles`', function () {
it('can be tested', function (done) {

@@ -34,3 +34,3 @@ flow(

describe('read function', function () {
describe('function `read`', function () {
it('can be tested', function (done) {

@@ -37,0 +37,0 @@ flow(

@@ -8,3 +8,3 @@ 'use strict';

exports.name = 'nue';
exports.version = '0.2.0';
exports.version = '0.3.0';
exports.flow = flow;

@@ -88,3 +88,3 @@

if (err) {
callerContext._endWithErr.call(callerContext, err);
callerContext.endWith.call(callerContext, err);
} else {

@@ -113,3 +113,3 @@ callerContext.next.apply(callerContext, args);

}
StepContext.prototype._endWithErr.call(context, e);
StepContext.prototype.endWith.call(context, e);
}

@@ -175,2 +175,3 @@ } else if (context instanceof LastStepContext) {

this.end = this.end.bind(this);
this.endWith = this.endWith.bind(this);
this.async = this.async.bind(this);

@@ -184,11 +185,2 @@ }

return (function makeCallback(args, asyncIndex) {
function flatten(array) {
var results = [];
array.forEach(function (array2) {
array2.forEach(function (e) {
results.push(e);
});
});
return results;
}
return function (err) {

@@ -199,7 +191,13 @@ self._asyncCallCount--;

self._isAsyncCanceled = true;
self._endWithErr.call(self, new NueAsyncError(err, self.flowName, self.stepName, self._step.stepIndex, asyncIndex));
self.endWith.call(self, new NueAsyncError(err, self.flowName, self.stepName, self._step.stepIndex, asyncIndex));
} else {
self._results[asyncIndex] = args.concat(Array.prototype.slice.call(arguments, 1));
if (self._asyncCallCount === 0) {
self.next.apply(self, flatten(self._results));
self.next.apply(self, self._results.map(function (array) {
switch(array.length) {
case 0: return undefined;
case 1: return array[0];
default: return array;
}
}));
}

@@ -221,3 +219,3 @@ }

this.end = noop;
this._endWithErr = noop;
this.endWith = noop;
this._flow.err = null;

@@ -231,3 +229,3 @@ this._flow.args = Array.prototype.slice.call(arguments);

this.end = noop;
this._endWithErr = noop;
this.endWith = noop;
this._flow.err = null;

@@ -238,6 +236,6 @@ this._flow.args = Array.prototype.slice.call(arguments);

StepContext.prototype._endWithErr = function _endWithErr(err) {
StepContext.prototype.endWith = function endWith(err) {
this.next = noop;
this.end = noop;
this._endWithErr = noop;
this.endWith = noop;
this._flow.err = err;

@@ -257,3 +255,3 @@ this._flow.args = [];

this.end = noop;
this._endWithErr = noop;
this.endWith = noop;
this._step.events.emit('done', this.err, Array.prototype.slice.call(arguments));

@@ -265,11 +263,11 @@ };

this.end = noop;
this._endWithErr = noop;
this.endWith = noop;
this._step.events.emit('done', this.err, Array.prototype.slice.call(arguments));
};
LastStepContext.prototype._endWithErr = function _endWithErr(err) {
LastStepContext.prototype.endWith = function endWith(err) {
this.next = noop;
this.end = noop;
this._endWithErr = noop;
this.endWith = noop;
this._step.events.emit('done', err, []);
};

@@ -12,3 +12,3 @@ {

},
"version" : "0.2.0"
"version" : "0.3.0"
}

@@ -33,2 +33,3 @@ nue — An async control-flow library

);
myFlow('file1', 'file2');

@@ -51,13 +52,14 @@ ```

* `next`: Function. A function to execute a next function immediately.
* `async`: Function. A function to accept parameters for a next function and return a callback.
* `end`: Function. A function to execute a last function to end a control-flow.
* `data`: Object : A object to share arbitrary data between functions in a control-flow.
* `args`: Array : An array equivalent to `arguments` for a function.
* `next`: Function. A function to execute a next step immediately.
* `async`: Function. A function to accept parameters for a next step and return a callback.
* `end`: Function. A function to execute a last step immediately to end a control-flow.
* `endWith`: Function. A function to execute a last step immediately with an error to end a control-flow. The first parameter is an error object. The error object is referred as `this.err` in a last step.
* `data`: Object : A object to share arbitrary data between steps in a control-flow.
* `args`: Array : An array equivalent to `arguments` for a step except this is real Array.
* `flowName`: String : flow name.
* `stepName`: String : step name.
In addition to the above ones, the context of the last function has a following property.
In addition to above ones, the context of a last step has a following property.
* `err`: Object. An object represents an error which is thrown explicitly or passed to an async callback as first argument.
* `err`: Object. An object represents an error which is thrown with `throw`, passed to `this.endWith` or passed to an async callback as first argument.

@@ -109,11 +111,11 @@ ### flow(String flowName) -> Function

var myFlow = flow('myFlow')(
function (file1, file2) {
function readFiles(file1, file2) {
fs.readFile(file1, 'utf8', this.async(file1));
fs.readFile(file2, 'utf8', this.async(file2));
},
function (file1, data1, file2, data2) {
console.log(file1 + ' and ' + file2 + ' have been read.');
this.next(data1 + data2);
function concat(data1, data2) {
console.log(data1[0] + ' and ' + data2[0] + ' have been read.');
this.next(data1[1] + data2[1]);
},
function (data) {
function end(data) {
if (this.err) throw this.err;

@@ -137,9 +139,9 @@ console.log(data);

var myFlow = flow('myFlow')(
function (files) {
function readFiles(files) {
process.nextTick(this.async(files));
files.forEach(function (file) {
fs.readFile(file, 'utf8', this.async());
}.bind(this));
}, this);
},
function (files) {
function concat(files) {
var data = this.args.slice(1).join('');

@@ -149,3 +151,3 @@ console.log(files.join(' and ') + ' have been read.');

},
function (data) {
function end(data) {
if (this.err) throw this.err;

@@ -163,3 +165,3 @@ console.log(data);

Each function in a flow can share data through `this.data`.
Each step in a flow can share data through `this.data`.
`this.data` is shared in a same flow.

@@ -173,3 +175,3 @@ A nesting flow and any nested flows can't share `this.data`.

var myFlow = flow('myFlow')(
function (file1, file2) {
function readFiles(file1, file2) {
this.data.file1 = file1;

@@ -180,6 +182,6 @@ this.data.file2 = file2;

},
function (data1, data2) {
function concat(data1, data2) {
this.next(data1 + data2);
},
function (data) {
function end(data) {
if (this.err) throw this.err;

@@ -197,3 +199,3 @@ console.log(data);

In a last function in a flow, `this.err` represents an error which is thrown explicitly or passed to an async callback as first argument.
In a last step in a flow, `this.err` represents an error which is thrown with `throw`, passed to `this.endWith` or passed to an async callback as first argument.
To indicate error handling completion, you must assign `null` to `this.err`.

@@ -206,15 +208,15 @@

var myFlow = flow('myFlow')(
function (file1, file2) {
if (!file1) throw new Error('file1 is illegal.');
if (!file2) throw new Error('file2 is illegal.');
function readFiles(file1, file2) {
if (!file1) this.endWith(new Error('file1 is illegal.'));
if (!file2) this.endWith(new Error('file2 is illegal.'));
fs.readFile(file1, 'utf8', this.async());
fs.readFile(file2, 'utf8', this.async());
},
function (data1, data2) {
function concat(data1, data2) {
this.next(data1 + data2);
},
function (data) {
function end(data) {
if (this.err) {
// handle error
console.log(this.err);
console.log(this.err.message);
// indicate error handling completion

@@ -241,3 +243,3 @@ this.err = null;

var concatFiles = flow('concatFiles')(
var concatFiles = flow(
function (file1, file2) {

@@ -258,3 +260,3 @@ fs.readFile(file1, 'utf8', this.async());

describe('concatFiles flow', function () {
describe('flow `concatFiles`', function () {
it('can be tested', function (done) {

@@ -272,3 +274,3 @@ flow(

describe('read function', function () {
describe('function `read`', function () {
it('can be tested', function (done) {

@@ -275,0 +277,0 @@ flow(

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