Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Michael Erskine
    @msemtd
    Currently I'm adding try/catch to all waterfall and series functions and it's looking very boilerplate-y!
    David Staley
    @DServy
    has anyone had any luck doing async/await TS with async? something like
    async doSomething(array){
      return await async.map(array,iterator(item))
    }
    Operations Research Engineering Software+
    @ORESoftware
    @DServy async lib is strictly CPS style only for better or worse. (It's for better). You can await Promise.all()...async/await requires asynchronous code to use promises.
    @msemtd can you link to a github gist? I can help you
    Tiago Jesus
    @tiagofilipe12

    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()
         console.log(array)
         addAllNodes(array, () => {
         running--
         if (json.nodes.length > 0) {
           scheduler()
          }
        })
        running++
      }
    }
    
    scheduler()

    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(){
        renderGraph()
      }
      // attempting to queue json.links, which are the links to be added to the graph AFTER adding the nodes to the graph
      queue2.push(json.links)
    }
    // attempting to queue json.nodes which are basically the nodes I want to add first to the graph
    queue.push(json.nodes)
    Tiago Jesus
    @tiagofilipe12
    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
    @hargasinski

    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
      async.setImmediate(callback);
    }, (err) => {
      if (err) {
        // error handling
      }
      // similar function for links
      // the final callback for links should call renderGraph
    });
    David Staley
    @DServy
    @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
    @tiagofilipe12
    @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
    @sayanarijit

    I'm new to node/async

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

    Result:

    -> node test.js
    a
    b

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

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

    @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) {
      console.log(x)
      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
    @tushar-rishav

    Hi,
    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
    @tushar-rishav
    :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
    @SET001
      const p = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(1);
        }, 20000);
      });
    
      async.map(configs, async item => {
        const res = await p;
        console.log(item);
        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?
    Nikki
    @nikkitan
    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
    @yawetse
    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
    Nikki
    @nikkitan
    @yawetse Thanks!
    Yaw Etse
    @yawetse
    @nikkitan no prob, happy to help
    Nikki
    @nikkitan
    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
    @yawetse
    @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
    @SET001

    in this scenario

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

    why error handler does not triggered?

    Konstantin Kostiuk
    @SET001
    oh, it shold be like that await Promise.reject(new Error());
    Vamshi Gudavarthi
    @gudavarthi93_twitter
    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
    @Paskalouis
    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.
    atrok
    @atrok
    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?
    abuzarhamza
    @abuzarhamza
    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
    @rudimk
    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
    @PeterBocan
    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
    fetch(...)
       .then((results) => { 
         let list = ...
         async.mapLimit(list, async  (item) => ... ); 
         return ... ?
        /// ???     
      });
    Async doesn't return promises, can I use promisify?
    Peter Bocan
    @PeterBocan
    Anyway, is there a way, how to return the partial list even after there's an error from within mapLimit?
    Daniel Kats
    @boompig
    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
    @chriswells0
    Can async be used to wait for an async function's callback before continuing code execution?
    Joe Gornick
    @jgornick
    Hey folks, can I proivde a promise as a collection to a method like eachSeries?
    cindyshapiro
    @cindyshapiro
    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?
    joystick
    @joystick
    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!