Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Tiago Jesus

    Hello everyone, I am Tiago and I am developing an interactive visualization of DNA sequences using vivagraph.js. So I basically I have two lists (one for nodes and another one for links that freeze my browser (using firefox, but chrome also becomes slow), when I am adding the nodes and the links to the graph. So I have started playing around with some concurrency and queues to handle this. My idea was to limit the number of nodes and links being added simultaneously. First I started with something very simple:

    const addAllNodes = (array) => {
       // adds nodes using vivagraph functions
    const limit = 10
    let running = 0
    const scheduler = () => {
      while(running < limit && json.nodes.length > 0) {
         const array = json.nodes.shift()
         addAllNodes(array, () => {
         if (json.nodes.length > 0) {

    However this often results in too much recursion which is expected since I am running scheduler function inside itself.

    Then I started playing around with async, I have managed to use async.queue but it still freezes my browser and performance is pretty much the same as my implementation with no concurrency handling.
    So my test implementation is:
    var queue = async.queue(addAllNodes, 10)
    queue.drain = function(){
      // after getting all nodes, setup another concurrency for all links
      var queue2 = async.queue(addAllLinks, 10)
      queue2.drain = function(){
      // attempting to queue json.links, which are the links to be added to the graph AFTER adding the nodes to the graph
    // attempting to queue json.nodes which are basically the nodes I want to add first to the graph
    Tiago Jesus
    My idea was to add 10 nodes/links at a time and that all nodes are added before adding all links and only then execute renderGraph, which is a function to display the graph (basically).
    I might be doing something wrong yet, can you point me out the right direction to solve this? Thank you!
    Hubert Argasinski

    Hi @tiagofilipe12. To prevent the browser from freezing, make sure you aren't blocking the event loop. For example, if the vivagraph functions are synchronous, make sure you delay your calls to callback using async.setImmediate or a similar function.

    Also, as a side note, for an application like this, async.forEachLimit might be a better choice.

    async.forEachLimit(json.nodes, 10, (node, callback) => {
      // function for adding a single node
    }, (err) => {
      if (err) {
        // error handling
      // similar function for links
      // the final callback for links should call renderGraph
    David Staley
    @ORESoftware Thanks, that's what I figured. I would just need to wrap Async's stuff in my own promises. If you're using TypeScript. Async/Await is super helpful. Just wanted to see if someone has a promise wrapper for it that isn't 3 years old!
    Tiago Jesus
    @hargasinski Hmm ok, I will give it a try. And yes most likely I am blocking the event loop. async.forEachLimit looks suitable yeah... Thanks a lot! I will return to you (with sucessful results or not...) once I manage to come back to this code. Cheers
    Arijit Basu

    I'm new to node/async

    function echo(x) {
      return x
    list = ['a', 'b', 'c', 'd', 'e']
    async.concatLimit(list, 2, echo, x => console.log(x));


    -> node test.js

    Shouldn't it wait instead of discarding other elements? Also I callback didn't happen as I expected.

    Arijit Basu
    Ok I guess it's due to worker's console is different that what I am seeing.
    Hubert Argasinski

    @sayanarijit the iteratee, in this case echo, is passed a callback that it needs to invoke before async starts processing more items.

    function echo(x, callback) {
      callback(null, x)
    list = ['a', 'b', 'c', 'd', 'e']
    async.concatLimit(list, 2, echo, (err, results) => console.log(results))

    See the concatLimit docs for more info.

    Tushar Gautam

    I'm new to async and have been trying to figure out the working of filter method.
    Here's a sample code for filtering fields whose value is an odd number,

    var async = require('async');
    async.filter({a: 1, b: 2, c: 3}, function(num, callback) {
        callback(null, num & 1);
    }, function(err, results) {
        console.log(results, typeof results);

    It returns undefined 'undefined'. I am not sure what I'm doing wrong here. Would someone help me out? Thanks!

    Reading the underlying implementation, the iteratee expects a boolean in the callback.
    Tushar Gautam
    :point_up: It works in node v9.7.1 but not in node v6.9.1. Perhaps I missed to read the compatibility somewhere in the doc.
    Konstantin Kostiuk
      const p = new Promise((resolve, reject) => {
        setTimeout(() => {
        }, 20000);
      async.map(configs, async item => {
        const res = await p;
        return res;
      }, (err, result) => {
        console.log('^^^^', err, result);
    why in this code async.map callback never called? seems like it does not wait for p promise?
    Hi developers! Has the entire async library been integrated into the latest javascript?
    I'm asking because I was told by my team that the library has been integrated into new JS as the async/await feature, and so we're thinking to strip off caolan library completely and replace it by async/await.
    Yaw Etse
    Hi @nikkitan I think the short answer is no, the entire library has not been merge into the latest version onf javascript. the async library has a lot of useful methods for handling multiple asynchronous functions that use the default callback signature of (error, data). Async/Await in the newer versions of node provide a similar utility in the sense that, they make working with multiple asynchronous promises eaiser to work with.
    @nikkitan but the newest versions of node/javascript with Async/Await dont include asynchronous filter, map, series, and parallel methods. You can check out https://github.com/repetere/promisie which emulates what the async library does, except instead of expecting callback functions, it's expecting promises.
    Another popular alternative is bluebird
    @yawetse Thanks!
    Yaw Etse
    @nikkitan no prob, happy to help
    Is async lib ready to work on promises? I mean for example how can I call async.series on an array of Promises that I'm hoping to hook then and catch handlers in each cycle of a series?
    Yaw Etse
    @nikkitan I’ll message you separately but that’s exact what promisie does. It has many of the same async library utility functions but for promises
    Konstantin Kostiuk

    in this scenario

    eachSeries(webhooks, async (webhook) => {
          await Promise.reject();
        }, (e) => {
          //  error handler

    why error handler does not triggered?

    Konstantin Kostiuk
    oh, it shold be like that await Promise.reject(new Error());
    Vamshi Gudavarthi
    Hi, I am new to Async and I want to know to how to resolve the following problem. I have an async.series and an array of functions are passed in as input and there is one function in that where I need to invoke async.eachOfSeries, but async.eachOfSeries gets called only once for any array.
    I am assuming that async.series gets connected through invoking callback functions and same thing for async.eachOfSeries but each of these have their own callbacks to be invoked which is where I think the problem arises. ANy Ideas ?
    Paskalouis Patressi
    Hi, I just upgrade async from 2.1.4 to the latest. Is there any breaking changes ? Because my code on forEachSeries and forEachOfSeries, last callback is callback is not defined, like delayed.
    Folks, question about using async queues - i have 2 workers each doing its own stuff, and one depends on results of other. Both workers do some heavy stuff, and if run in a loop easily overwhelm the system. I hoped to run these workers in 2 queues, limiting the number of simultaneously executed workers. The task submitted to one queue once accomplished would push the second task to second queue, and both would execute its tasks in parallel. However, it has appeared that second queue wouldn't start execution of its tasks until first queue was done doing its own tasks. Why is that? Is it intended by design, or I'm missing something?
    Hi Folks .. one small question I need a small info for th usage of autoInject
    Here my code in the gist https://gist.github.com/abuzarhamza/03724d121f41bd410ba45a7bbbf97bff .. I have seen some time few people use currying to pass callback , Is it a good practice or should I use call?
    Rudraksh MK
    Hi there! I'm trying to hack async.js to run as the core of a workflow engine, where task definitions are essentially async.js function calls.
    I'm wondering if there's some kind of serialization method where a series of async.js calls can be serialized into a particular format - like JSON, for instance.
    Not sure if my question there makes sense, apologies!
    Peter Bocan
    Hey guys, I wonder how to correctly use async.mapLimit if I want return the list within a promise.then(...);
    I have something like this
       .then((results) => { 
         let list = ...
         async.mapLimit(list, async  (item) => ... ); 
         return ... ?
        /// ???     
    Async doesn't return promises, can I use promisify?
    Peter Bocan
    Anyway, is there a way, how to return the partial list even after there's an error from within mapLimit?
    Daniel Kats
    Hi all, quick question
    If I want to build the dist from source, how would I do that?
    I didn't see any instructions in the readme
    Chris Wells
    Can async be used to wait for an async function's callback before continuing code execution?
    Joe Gornick
    Hey folks, can I proivde a promise as a collection to a method like eachSeries?
    Can async.series be used with express?
    I've been using the library for a while now and I love it. It's incredibly elegant. But when I tried to use it within an app.get, it didn't wait for each function in the series to finish. It just moved on to the next one in the series and completely blew up my sequence. Thoughts?
    Alexei Kozhushkov
    Hello, need some help with async.queue please. Inside the worker function I have to wait on event coming from net socket. Is there any recipe how to do this? Thanks!

    Hello, how do I use async.queue in a sequential manner?

    I've read that for a static array of tasks, sequential execution can be achieved through async.series, if one requires push/pop, one should use queue instead. I've set up my queue as

    const RequestQueue = queue(() => {}, 1);

    but the 2nd item (a fetch request) always executes before the 1st item (also a fetch request) finishes.

    Sample Task:

     retrieveConnectionsTask = () => {
                .then(response =>
                .then(data => {
                    console.log("retrieveConnectionsTask Returned");
                .catch(error => console.log(error));

    would appreciate any advice.

    Thank you!

    Cory Mawhorter
    has anyone had any problems using async w/rollup? i've started seeing Cannot read property \'isAsync\' of undefined using parallelLimit but all the functions are asyncfunctions. i also tried wrapping them in asyncify but that didn't work either
    Nicolas Vanhoren

    Hello everyone.

    You might be interested by an open-source project I recently started which is basically a rewrite of Async.js but aimed for exclusive usage of async/await and promises.

    The code is here: https://github.com/nicolas-van/modern-async

    I would welcome any comment.

    Conrad Buck
    I also have been working on a replacement for some (but not all) parts of async. Mine is iter-tools, and it only focuses on iterables, but I think it has significant advantages. It ensures resources are released (by calling iterator.return() if it is present), it has a better approach to parallelization, and it offers more performant implementations of methods over sync iterators. In 8.0 I plan to change my methods around a bit so that import { asyncMap } from 'iter-tools' beceomes import { map } from 'iter-tools/async', which I think will be more familiar to users of this library.