Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 69 lines (59 sloc) 2.005 kB
6c40dfe @chjj first
authored
1 # $N - A flow control tool
2
3 $N is my attempt at making something similar to Step, but with less indentation
4 and slightly different syntax. $N is very light-weight and small, only a few lines,
5 so it is copy & pastable if need be.
6
7 ## Example Usage
8
9 $N(function(next) {
10 fs.readFile('./text.txt', 'utf-8', next);
11 })
12 .N(function(next, err, txt) {
13 if (err) {
14 console.log(err.message);
15 } else {
16 console.log('Some text: ' + txt);
17 }
18 next.N(function(next) { // you can even push more functions onto the stack!
19 console.log('world');
20 next();
21 }, function() { // you can pass multiple args if you want to use it like Step
22 console.log('how are you?');
23 })('hello'); // the same thing as calling next() when inside a stack
24 })
25 .N(function(next, hello) {
26 console.log(hello);
27 next();
28 })(); // execute the chain
29
30 ### Outputs:
31
32 Some text: [whatever text]
33 hello
34 world
35 how are you?
36
37 ## More Features
38
39 There's also an "N-features.js" file, which is something I'm experimenting with. It includes parallel calls and
40 consistent arguments with error handling, e.g. (err, data). I'm unsure whether I want to include these features,
41 I like keeping things simple.
42
43 $N(function() {
44 fs.readFile('./text1.txt', 'utf-8', this);
45 })
46 .N(function(err, text) {
47 if (err) {
48 console.log(err);
49 } else {
50 console.log('Some text: ' + text);
51 }
52 this.N(function(err, results) {
53 console.log('world');
54 this(results);
55 }, function(err, results) {
56 console.log('how are you?');
57 console.log('...even more text:', results);
58 })('hello');
59 })
60 .N(function(err, hello) {
61 if (err) console.log('oh no, an error:', err)
62 console.log(hello);
63 fs.readFile('./text2.txt', 'utf-8', this.para);
64 fs.readFile('./text3.txt', 'utf-8', this.para);
65 })();
66
67 ## License
68
69 See LICENSE for more info (MIT).
Something went wrong with that request. Please try again.