Coder Social home page Coder Social logo

Parallel example does not work! about async HOT 3 CLOSED

caolan avatar caolan commented on June 20, 2024
Parallel example does not work!

from async.

Comments (3)

 avatar commented on June 20, 2024

I'm trying to use this for async validations with an object of validations, like {email:.notNull().isEmail(), username: .len(5,20)}.

using async.parallel, it runs all the validations, but not asynchronously. no matter how long the first function (wrapping a chain of validations on one attribute) takes, it will always finish before the next function begins. do we have to call nextTick ourselves?

from async.

 avatar commented on June 20, 2024

I guess .parallel does not delegate to .nextTick(). Using a setTimeout within the tasks, they do run asynchronously, but otherwise they block. Should we call process.nextTick() ourselves then within the individual tasks?

`
taskDone = (num, cb)->
return ()->
console.log "Done with: " + num
cb(null, "This is " + num)

tTasks = 
  zero: (cb) ->
    # ONLY THIS BLOCKS
    console.log "Starting ZERO"
    now = new Date().getTime()
    while(new Date().getTime() < now + 4000)
      a = 1
    taskDone("zero", cb)()
  one: (cb)-> 
    console.log "Starting ONE"
    setTimeout(taskDone("one", cb), 1000)
  two: (cb)-> 
    console.log "Starting TWO"
    setTimeout(taskDone("two", cb), 0)

tChecked = (err, results)-> console.log "Done: " + JSON.stringify(results)

async.parallel(tTasks, tChecked)   

`

Returns:

Starting ZERO
Done with: zero
Starting ONE
Starting TWO

Done with: two
Done with: one
Done: {"zero":"This is zero","two":"This is two","one":"This is one"}

from async.

ianwalter avatar ianwalter commented on June 20, 2024

The docs have been updated explaining that this is the intended functionality.
Someone should close this issue.

from async.

Related Issues (20)

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.