Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simpleasync

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simpleasync - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

sample8.js

71

lib/simpleasync.js

@@ -22,8 +22,40 @@

var newdata = [];
var fnl = fn.length; var objcount = { count: 0 };
for (var j = 0; j < fnl; j++) { var sfn = fn[j]; if (sfn.length > 1) { sfn(data, makecb(j, objcount, fnl)); } else {
newdata[j] = fn[j](data); objcount.count++; } }
if (objcount.count >= fnl) {
var fnl = fn.length;
var objcount = { count: 0 };
for (var j = 0; j < fnl; j++) {
var sfn = fn[j];
if (sfn.length > 1) {
sfn(data, makecb(j, objcount, fnl));
}
else {
newdata[j] = sfn(data);
objcount.count++;
}
}
if (objcount.count >= fnl) {
data = newdata;
setImmediate(doStep); } function makecb(nbucket, objcount, count) { return function (err, newd) { if (err) { catchfn(err); return; } newdata[nbucket] = newd; objcount.count++; if (objcount.count >= count) { data = newdata; setImmediate(doStep); } } }
setImmediate(doStep);
}
function makecb(nbucket, objcount, maxcount) {
return function (err, newd) {
if (err) {
catchfn(err);
return;
}
newdata[nbucket] = newd;
objcount.count++;
if (objcount.count >= maxcount) {
data = newdata;
setImmediate(doStep);
}
}
}
return;

@@ -35,2 +67,29 @@ }

if (fn.map.length > 1) {
var count = 0;
var dl = data.length;
for (var n in data)
fn.map(data[n], makecbmap(n));
function makecbmap(n) {
return function (err, newvalue) {
if (err) {
catchfn(err);
return;
}
newdata[n] = newvalue;
count++;
if (count >= dl) {
data = newdata;
setImmediate(doStep);
}
}
}
return;
}
for (var n in data)

@@ -41,2 +100,3 @@ newdata[n] = fn.map(data[n]);

setImmediate(doStep);
return;

@@ -68,3 +128,2 @@ }

function Sequence() {

@@ -71,0 +130,0 @@ var fns = [];

2

package.json
{ "name": "simpleasync"
, "description": "Simple flow library to chain and run functions with asynchronous calls"
, "keywords": [ "node", "asynchronous", "library" ]
, "version": "0.0.2"
, "version": "0.0.3"
, "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" }

@@ -150,2 +150,20 @@ # SimpleAsync

`map` accepts function with callback, too:
```js
async()
.do(function (data, next) { next(null, data + 1); })
.do(function (data, next) { next(null, data + 2); })
.do(function (data, next) { next(null, data + 3); })
.map(function (data, next) { next(null, data * data); })
.then(function (data) {
console.dir(data);
})
.run(1);
```
Expected output
```
[ 4, 9, 16 ]
```
## Development

@@ -171,2 +189,4 @@

- 0.0.1: Published
- 0.0.2: Published
- 0.0.3: Published. do with sync and async functions. map async function support

@@ -173,0 +193,0 @@ ## License

var async = require('..');
exports['then one step'] = function (test) {
exports['map and then'] = function (test) {
test.async();

@@ -27,1 +27,25 @@

}
exports['map with async fn and then'] = function (test) {
test.async();
var total = 0;
var seq = async()
.map(function (item, next) {
next(null, item * item);
})
.then(function (data) {
test.ok(data);
test.ok(Array.isArray(data));
test.equal(data.length, 3);
test.equal(data[0], 1);
test.equal(data[1], 4);
test.equal(data[2], 9);
test.done();
});
test.ok(seq);
test.strictEqual(seq.run([1,2,3]), seq);
}
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