Socket
Socket
Sign inDemoInstall

twostep

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.4.1

2

package.json
{
"name": "twostep",
"description": "Simple control-flow library for node.js that makes parallel execution, serial execution and error handling painless.",
"version": "0.4.0",
"version": "0.4.1",
"author": "2do2go team <dev.2do2go@gmail.com>",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -15,3 +15,3 @@ # TwoStep

* simplified error handling for common use case (when error handled at the
last step) using Steppy (see details below)
last step)
* ability to pass the arbitrary values between steps (using `this.pass()`)

@@ -36,8 +36,3 @@ * pure js code (no dependencies, < 200 lines of code)

passing value to the next step or `this.makeGroup()` for creating group (for
calling `slot()` or `pass()` for the group and having results
grouped to array) can be called. If error is occured inside step it will be
passed to the next step as first argument. First argument of the step is
always an error (falsy if no error), subsequent arguments - results of calls
accepted by `this.pass()`, `this.slot()` or `this.makeGroup()` in the order
they were called at previous step.
having results grouped to array) can be called.

@@ -98,13 +93,80 @@ ```js

pass the error (if it exists) to the next step for handle the error at the last
step. We can simply avoid writing this annoying line using `Steppy` (can be
imported as `var Steppy = require('twostep').Steppy`) instead of
`Step`. `Steppy` automatically wraps every single step with error check and
calls the last step if error occurs.
step. We can avoid writing this annoying line using `Steppy`. With `Steppy`
example described above transforms to
Created group has same api as `this` but if `pass()` or `slot()` was
not called for the group empty array will be passed to the next step as group result.
If `this.pass()`, `this.slot()` or `this.makeGroup()` will not be called then
next step will never be called.
```js
var Steppy = require('twostep').Steppy,
fs = require('fs');
Steppy(
function() {
this.pass(__filename + '.bak');
fs.readFile(__filename, 'utf8', this.slot());
},
function(err, bakFile, content) {
this.pass(bakFile);
fs.readdir(__dirname, this.slot());
fs.writeFile(bakFile, content, this.slot())
},
function(err, bakFile, dirContent) {
console.log('%s successfully written', bakFile);
this.pass(dirContent);
var group = this.makeGroup();
dirContent.forEach(function(name) {
fs.stat(name, group.slot());
});
},
function(err, dirContent, stats) {
var fileNames = dirContent.filter(function(name, i) {
return stats[i].isFile();
});
console.log('files in dir: %s', fileNames);
},
function(err) {
console.log('Error occured: ', err.stack || err);
process.exit(1);
}
);
```
## API
### Step(step1, step2, stepN...)
Steps container accepts functions and executes them in series. If error is
occured inside step it will be passed to the next step as first argument. First
argument of the step is always an error (falsy if no error), subsequent
arguments - values passed to the reserved slots (created via `this.pass()`,
`this.slot()` or `this.makeGroup()`) of previous step in the order the slots
were reserved.
### Steppy(step1, step2, stepN...)
Same steps container as `Step` but it also automatically wraps every single step
with error check and calls the last step if error occurs.
### Methods which can be called inside each step
#### this.slot()
Reserves one slot at the current step. Next step will be called when
all reserved slots of current step will be filled with data or the error occurs.
Returns callback `function(err, data)` to fill the slot with data.
#### this.pass(value1, value2, valueN...)
Passes one or several synchronous values to the next step.
#### this.makeGroup()
Reserves slot, creates and returns a group, all results of which will be passed
into the reserved slot as a single array. `pass`, `slot` methods can be called
for created group. If group methods were not called empty array will be passed
into reserved slot.
## Tests

@@ -130,3 +192,3 @@

detailed coverage report will be accessible at ./coverage/index.html
detailed coverage report will be saved at ./coverage/index.html

@@ -133,0 +195,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc