suguru03 / neo-async Goto Github PK
View Code? Open in Web Editor NEWNeo-Async is thought to be used as a drop-in replacement for Async, it almost fully covers its functionality and runs faster
License: Other
Neo-Async is thought to be used as a drop-in replacement for Async, it almost fully covers its functionality and runs faster
License: Other
This would make it so you don't have weird errors where the callback is not where you expected it to be because you got the argument list wrong. Would also allow you to completely ignore arguments for some tasks. Will also allow you to use async.apply
in the middle of a waterfall.
I've opened this issue in async as well (caolan/async#895), but there might be more of a chance to make an API breaking change here.
The code below works with caolan/async v3.2.0 and with suguru03/neo-async v1.8.2 and outputs
Arguments passed from 'each()' callback: [Arguments] { '0': [Function] }
Arguments passed from 'waterfall()' callback: [Arguments] { '0': null }
However after updating suguru03/neo-async to v2.6.2 it will crash, and only work if the "res" argument is added to the "step2" function. The output is now different:
Arguments passed from 'each()' callback: [Arguments] { '0': undefined, '1': [Function: next] }
Arguments passed from 'waterfall()' callback: [Arguments] { '0': null, '1': undefined }
It appears this breaking changes was introduced by the new once() methods in
commit bd0fb377579bcd83b7ef5b155bf55668c6b4788f
Author: Suguru Motegi <[email protected]>
Date: Sat Sep 29 19:49:26 2018 -0700
and the original behaviour seems to be correct and desired, since the new argument is always 'undefined'.
Here's the test code:
const order = [];
const array = [1, 3, 2];
async.waterfall([
function step1(callback) {
async.each(
array,
function iterator(num, done) {
setTimeout(function() {
order.push(num);
done();
}, num * 10);
},
callback
);
},
function step2(/*res, */callback) {
console.log("Arguments passed from 'each()' callback:", arguments);
callback(null);
}
], function done(err) {
console.log("Arguments passed from 'waterfall()' callback:", arguments);
process.exit();
});
With the rapid inclusion of new version of V8 in Node's renewed development cycle--and ES7 features being rapidly included as well--it makes sense to no longer encourage using async
as the library's import name as it will soon become a JS keyword.
Perhaps encourage neoAsync
, neoasync
, or nasync
instead?
Starting development server...
66% building 782/834 modules 52 active /Users/snnmeatball/Documents/zhojun/dev/personalCenter/pc/node_modules/core-js/modules/_object-keys.js/Users/snnmeatball/Documents/zhojun/dev/personalCenter/pc/node_modules/neo-async/async.js:16
throw new Error('Callback was already called.');
Error: Callback was already called.
at throwError (/Users/snnmeatball/Documents/zhojun/dev/personalCenter/pc/node_modules/neo-async/async.js:16:11)
at /Users/snnmeatball/Documents/zhojun/dev/personalCenter/pc/node_modules/neo-async/async.js:2818:7
at processTicksAndRejections (node:internal/process/task_queues:75:11)
fyi, async v1.0.0 has been released: https://github.com/caolan/async/releases/tag/1.0.0
I do not know what difference of async v0.9.0..v1.0.0 but, neo-async should update speed comparison and docs.
Thanks
I think under the server side result you meant to write neo-async/a sync for the radio, not async/neo-async
Otherwise this implies that neo-async is way shower, wench I don't think is true.
Hi, I read your docs and codes, and now I believe that async.angelFall
is really good function, which is a good replacement of async.waterfall
and more robust.
There are many async.waterfall
in my project but async.angelFall
is more desirable in many cases, so I decieded to do async.waterfall = async.angelFall;
π―
I appreciate your nice work.
I think that async.angelFall
should supersede async.waterfall
in the next major version: i.e. async.waterfall = async.angelFall
. How do you think of it?
Sorry for my poor English.
I would like to ask if it is possible to cancel an active running task (not the ones waiting to be processed).
Thank you π
var mapLimit = require("neo-async/mapLimit");
Doesn't seem to work. Could be a good feature to add.
I haven't had a chance to look through and figure out what has changed with eachSeries between 1.2.x and 1.3.x, but I have noticed there is a severe performance regression (to the point of it being unusable). It is easily reproducible with the following fiddles:
1.2.1 - http://jsfiddle.net/4vg8p84w/
1.3.2 - http://jsfiddle.net/j3r5az56/
const assert = require('assert'),
async = require('neo-async');
function *makeGen(arr) {
let idx = 0;
let len = arr.length;
while (idx < len) {
yield arr[idx];
idx += 1;
}
}
const LIMIT = 2;
const INPUT = ['abc', 'def', 'ghi', 'jkl'];
const gen = makeGen(INPUT);
async.mapLimit(gen, LIMIT, (v, cb) => {
setTimeout(() => {
console.log(`processing: ${v}`);
cb(undefined, v);
}, Math.round(Math.random()*1000));
}, (err, results) => {
assert(!err, err);
console.log(`ACTUAL: ${results}`);
assert.strict.deepEqual(results, INPUT);
});
Results with neo-async:
processing: abc
processing: def
processing: jkl
processing: ghi
Results with async:
processing: abc
processing: def
processing: jkl
processing: ghi
ACTUAL: abc,def,ghi,jkl
Line 8355 in b449ec0
shouldn't it be case 'function'
?
Hi, can you please check?
Encryption keys should never be null and should be obfuscated and managed in an external source. Storing encryption keys, null or otherwise, in plain text anywhere on the system allows anyone with sufficient permissions to read and potentially misuse the encryption key.
Example code where error is thrown:
function createCallback(value, key) {
return function(err, res) {
if (key === null) {
throwError();
}
if (err) {
key = null;
iterate = noop;
callback = once(callback);
callback(err, objectClone(result));
return;
}
if (!!res === bool) {
result[key] = value;
}
key = null;
if (++completed === size) {
iterate = throwError;
callback = onlyOnce(callback);
callback(null, result);
} else if (sync) {
nextTick(iterate);
} else {
sync = true;
iterate();
}
sync = false;
};
}
Hello, is it possible to incorporate the LICENSE file inside the npm package ? Now it's missing. It's implied by MIT license that if licensed under the MIT the source code must be accompanied by full license text. If the license file is not in the npm package a lot of people cannot use it.
Thank you
ie 11 support?
Hi, here I faced new deprecation warning
[DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_HASH]
DeprecationWarning: [hash] is now [fullhash] (also consider using [chunkhash] or [contenthash],
see documentation for details)
occurred at arrayEach
in (node_modules/neo-async/async.js:2405:9)
Thanks:pray:
When
each
Set
callback
in a sync way in the iteratorit incorrectly calls the iterator for the new items after the method completed.
const async = require("neo-async")
const s = new Set([1, 2, 3, 4]);
async.each(s, (i, callback) => {
console.log(i);
callback();
}, () => {
console.log("done");
s.add(5);
});
1
2
3
4
done
5
Hi, I've a function that stats some files. during tests I stub that function so it no longer is asyncronous. with neo-async 1.2.1 the tests work correctly, but with async 1.3.1 the tests give an error.
here's a small coffee program that is capable of replicating the problem
async = require 'neo-async'
names = [ 'dir1', 'dir2', 'file1', 'file2' ]
stubbedFunction = (name, callback) ->
result = name.charAt(0) is 'd'
callback null, result
tasks =
dirs: async.filter.bind null, names, stubbedFunction
files: async.reject.bind null, names, stubbedFunction
async.parallel tasks, (err, result) ->
console.log result
~ coffee test.coffee
{ dirs: [ 'dir1', 'dir2' ], files: [ 'file1', 'file2' ] }
~ npm uninstall neo-async
unbuild [email protected]
~ npm install neo-async
[email protected] node_modules/neo-async
~ coffee test.coffee
Error: Callback was already called.
at throwError (/Users/matteo/test/node_modules/neo-async/lib/async.js:9:11)
at /Users/matteo/test/node_modules/neo-async/lib/async.js:7076:13
at commonFilter (/Users/matteo/test/node_modules/neo-async/lib/async.js:3400:30)
at baseEachFunc (/Users/matteo/test/node_modules/neo-async/lib/async.js:2691:20)
at Object.parallel (/Users/matteo/test/node_modules/neo-async/lib/async.js:7067:9)
The result from detectSeries() (and I suppose detect() and detectLimit() too) is different between neo-async 1.8 and neo-async 2.0. here's an example:
var async = require('neo-async');
function iterator(obj, done) {
if (obj.id === 1) {
done(true);
} else {
done(false);
}
}
var elements = [
{ id: 3 },
{ id: 2 },
{ id: 1 },
{ id: 4 }
];
async.detectSeries(elements, iterator, function(result) {
console.log(result);
});
with neo-async 1.8 this is the output of the script:
bash-3.2$ npm --depth=0 ls | grep neo
βββ [email protected]
bash-3.2$ node test.js
{ id: 1 }
with neo-async 2.0 this is the output of the same script:
bash-3.2$ npm --depth=0 ls | grep neo
βββ [email protected]
bash-3.2$ node test.js
true
I have test neo-async with async test case, it didn't pass. I know there may be some test case relate to detail logic, so it didn't pass.
Just wondering if there is a difference between async.angelfall and async.waterfall
async.cascade is also a good name, by the way.
If TypeError
was caused, functions should avoid double callback.
var called = false;
async.map([1, 2], function(item, callback) {
try {
callback(item);
} catch (exception) {
try {
callback(exception);
} catch(e) {
assert.ok(e); // Callback was already called.
done();
}
}
}, function(err) {
assert.ok(err);
assert.strictEqual(called, false);
called = true;
async.nothing();
});
I looked through the codebase, it seems that there are a lot of references to Array.prototype.shift.
The problem with shift/unshift is that they go through the whole array and update the indices.
In short, pop/push is O(1), but shift/unshift are O(N). See:
{
const size = 100000;
const v = new Array(size).fill(null);
const shiftStart = Date.now();
for(let i = 0; i < size; i++){
v.shift();
}
console.log('shift time:', Date.now() - shiftStart);
}
{
const size = 100000;
const v = new Array(size).fill(null);
const popStart = Date.now();
for(let i = 0; i < size; i++){
v.pop();
}
console.log('pop time:', Date.now() - popStart);
}
you will see this output:
shift time: 933
pop time: 1
You should strive to use a linked-list for queues instead of a simple JavaScript array.
A linked-list can do things in constant time etc.
The difference in performance is mostly noticeable for very large arrays, but if you want to squeeze performance, this is a good place to do so.
neo-async@v2
should cover all async
test cases.
https://github.com/suguru03/async
I'd be willing to help out.
changelog
This issue #988 was fixed in async v1.5.1 but still exist in neo-async.
Throw an exception when async.auto calls back with an error Error: async.auto task has cyclic dependencies
.
While doing npm start I am getting the error in node_modules\neo-async\async.js:14:11
throw new Error('Callback was already called.');
Also this:
12% building modules 19/19 modules 0 activeΓ ο½’wdmο½£: Error: No module factory available for dependency type: ContextElementDependency
My package.json:
{
"name": "sample-app-angular-hybrid",
"description": "Architecture overview demo for Angular UI-Router",
"version": "1.0.2",
"scripts": {
"clean": "shx rm -rf _bundles transpiled",
"start": "npm run serve",
"serve": "webpack-dev-server --open --progress",
"build": "npm run clean && webpack --mode=production --progress",
"test": "npm run build && cypress-runner run --path .",
"test:open": "npm run build && cypress-runner open --path .",
"gh-pages": "git checkout gh-pages && git rebase master && rm -rf node_modules && yarn install && webpack && git add -f _bundles && git commit -m 'publish gh-pages' && git push origin gh-pages:gh-pages --force && git checkout master"
},
"contributors": [
{
"name": "Chris Thielen",
"web": "https://github.com/christopherthielen"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ui-router/sample-app-angular-hybrid.git"
},
"dependencies": {
"@angular/common": "^6.0.9",
"@angular/compiler": "^6.0.9",
"@angular/compiler-cli": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.0.9",
"@angular/router": "^6.1.0",
"@angular/upgrade": "^6.0.9",
"@uirouter/angular-hybrid": "^6.0.1",
"@uirouter/visualizer": "^6.0.2",
"angular": "^1.7.2",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",
"webpack": "^4.16.3",
"webpack-dev-server": "^3.1.5",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "^6.1.1",
"@ngtools/webpack": "^6.1.1",
"@types/angular": "^1.6.49",
"@uirouter/cypress-runner": "^1.0.9",
"shx": "^0.3.2",
"source-map-loader": "^0.2.3",
"typescript": ">=2.7.2 <2.8.0",
"webpack-cli": "^3.1.0"
}
}
neo-async/async.js has the throwError
function which is called several times. It will help if this function takes a parameter and shows exactly what error was there.
15 var throwError = function throwError() {
16 throw new Error('Callback was already called.');
17 };
Example, in the following snippet same function is used for different errors.
3828 return function(err, res) {
3829 if (index === null) {
3830 throwError();
3831 }
3832 if (err) {
3833 index = null;
3834 iterate = noop;
3835 callback = once(callback);
3836 callback(err, createArray(result));
3837 return;
3838 }
3839 result[index] = res;
3840 index = null;
3841 if (++completed === size) {
3842 iterate = throwError;
3843 callback(null, result);
3844 callback = throwError;
3845 } else if (sync) {
3846 nextTick(iterate);
3847 } else {
I'm getting the following error but I cant figure out the call stack, if the error message were helpful that'd be great.
Error: Callback was already called.
at throwError (/home/node_modules/neo-async/async.js:16:11)
at /home/node_modules/neo-async/async.js:2818:7
at processTicksAndRejections (internal/process/task_queues.js:79:11)
What are the long-term plans for neo-async? Is it supposed to stay an own project or will you strive for integration into async in the future?
I noticed this by complete chance!
Line 1 in c1dca33
package.json only mentions these as files,
"files": [
"LICENSE",
"index.js",
"lib/async.js",
"lib/async.min.js",
"dist/async.js",
"dist/async.min.js"
],
but npm dist tarballs has many files, there is no documentation on how to generate those other files and in debian, we need to build from source.
Is this generated using lodash-cli like https://salsa.debian.org/js-team/node-lodash/-/blob/master/debian/rules?ref_type=heads#L14 ?
more https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1064411
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.