GithubHelp home page GithubHelp logo

suguru03 / neo-async Goto Github PK

View Code? Open in Web Editor NEW
648.0 648.0 46.0 3.86 MB

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

Makefile 0.06% JavaScript 99.94%
async javascript neo-async nodejs

neo-async's People

Contributors

chengcyber avatar danielruf avatar dannygriffin000 avatar dependabot[bot] avatar e-jigsaw avatar exx8 avatar fossabot avatar genisysram avatar greenkeeperio-bot avatar opichals avatar oresoftware avatar proyang avatar sokra avatar stevepeak avatar suguru03 avatar xcorail avatar yles9056 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo-async's Issues

waterfall tasks should take callback first

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.

Undocumented breaking change (now incompatible with caolan/async)

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();
});

Consider discouraging using `async` as import name

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?

Callback was already called.

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)

Readme error

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.

async.angelFall is much nicer than async.waterfall

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.

mapLimit of Generator doesn't invoke final callback

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

Fortify Security Scan Shows Null Security Key Issue

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;
};
}

Missing LICENSE file in npm package

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

webpack deprecation warning

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:

(sync) iterator called after finish with Sets

When

  • using each
  • with a Set
  • calling the callback in a sync way in the iterator
  • and adding items in the callback in a sync way

it 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

bug with `async.filter` and `async.reject`

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)

neo-async 2.0 is incompatible with 1.8

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

Avoid double callback

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();
});

Important - Avoid Array.prototype.shift/unshift

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.

Callback was already called in async.js

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:throwError doesnt display very useful error for all cases.

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)

document how generate all files present in npm dist tarball

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.