simpleasync
Advanced tools
Comparing version 0.0.3 to 0.0.4
function Runner(fns, catchfn) { | ||
function SimpleStep(step, fn) { | ||
var failfn = null; | ||
this.run = function (data, cbok, cbfail) { | ||
if (step) | ||
step.run(data, function (newdata) { | ||
var result = fn(newdata); | ||
cbok(result); | ||
}, function (err) { | ||
if (failfn) | ||
failfn(err); | ||
else if (cbfail) | ||
cbfail(err); | ||
else | ||
throw err; | ||
}); | ||
else { | ||
var result = fn(data); | ||
cbok(result); | ||
} | ||
} | ||
function dostep(step, data, cbok, cbfail) { | ||
step.run(data, function (newdata) { | ||
dofn(newdata, cbok, cbfail); | ||
}, function (err) { | ||
doerror(err, cbfail); | ||
}); | ||
} | ||
function dofn(data, cbok, cbfail) { | ||
try { | ||
var result = fn(data); | ||
cbok(result); | ||
} | ||
catch (err) { | ||
doerror(err, cbfail); | ||
} | ||
} | ||
function doerror(err, cbfail) { | ||
if (failfn) | ||
failfn(err); | ||
else if (cbfail) | ||
cbfail(err); | ||
else | ||
throw err; | ||
} | ||
} | ||
function Runner(fns, failfn) { | ||
var k = 0; | ||
@@ -46,3 +96,3 @@ var l = fns.length; | ||
if (err) { | ||
catchfn(err); | ||
failfn(err); | ||
return; | ||
@@ -77,3 +127,3 @@ } | ||
if (err) { | ||
catchfn(err); | ||
failfn(err); | ||
return; | ||
@@ -107,3 +157,3 @@ } | ||
if (err) { | ||
catchfn(err); | ||
failfn(err); | ||
return; | ||
@@ -122,3 +172,3 @@ } | ||
catch (err) { | ||
catchfn(err); | ||
failfn(err); | ||
return; | ||
@@ -132,3 +182,3 @@ } | ||
var catchfn = function (err) { | ||
var failfn = function (err) { | ||
throw err; | ||
@@ -155,4 +205,4 @@ } | ||
this.catch = function (fn) { | ||
catchfn = fn; | ||
this.fail = function (fn) { | ||
failfn = fn; | ||
return this; | ||
@@ -162,3 +212,3 @@ } | ||
this.run = function (data) { | ||
var runner = new Runner(fns, catchfn); | ||
var runner = new Runner(fns, failfn); | ||
setImmediate(runner.run(data)); | ||
@@ -170,4 +220,2 @@ | ||
function createSequence() { | ||
@@ -174,0 +222,0 @@ return new Sequence(); |
{ "name": "simpleasync" | ||
, "description": "Simple flow library to chain and run functions with asynchronous calls" | ||
, "keywords": [ "node", "asynchronous", "library" ] | ||
, "version": "0.0.3" | ||
, "version": "0.0.4" | ||
, "author": "Angel 'Java' Lopez <webmaster@ajlopez.com> (http://www.ajlopez.com)" | ||
@@ -6,0 +6,0 @@ , "repository": { "type": "git", "url": "git://github.com/ajlopez/SimpleAsync.git" } |
@@ -59,3 +59,3 @@ # SimpleAsync | ||
Use catch for catch errors: | ||
Use `fail` for catch errors: | ||
```js | ||
@@ -67,3 +67,3 @@ async() | ||
}) | ||
.catch(function (err) { | ||
.fail(function (err) { | ||
console.log('error:', err); | ||
@@ -87,3 +87,3 @@ }) | ||
}) | ||
.catch(function (err) { | ||
.fail(function (err) { | ||
console.log('error:', err); | ||
@@ -193,2 +193,3 @@ }) | ||
- 0.0.3: Published. do with sync and async functions. map async function support | ||
- 0.0.4: Published, fail function | ||
@@ -195,0 +196,0 @@ ## License |
@@ -8,5 +8,5 @@ var async = require('./lib/simpleasync'); | ||
}) | ||
.catch(function (err) { | ||
.fail(function (err) { | ||
console.log('error:', err); | ||
}) | ||
.run(10); |
@@ -8,5 +8,5 @@ var async = require('./lib/simpleasync'); | ||
}) | ||
.catch(function (err) { | ||
.fail(function (err) { | ||
console.log('error:', err); | ||
}) | ||
.run(10); |
@@ -56,3 +56,3 @@ | ||
}) | ||
.catch(function (err) { | ||
.fail(function (err) { | ||
test.ok(err); | ||
@@ -59,0 +59,0 @@ test.equal(err, 'error'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19057
429
206