1

i'm trying to get

testFunction: () ->
  console.log "testFunction"
  async.series(
    (->
      console.log "first"
    ),
    (-> 
      console.log "second"
    )
  )

i've also tried to no success

testFunction: () ->
  console.log "testFunction"
  async.series(
    (->
      console.log "first"
      return undefined
    ),
    (-> 
      console.log "second"
      return undefined
    )
  )

to run, i would expect console output of "testFunction", "first", "second" but I'm getting "testFunction", "second" and it seems like there is a problem with coffeescript's use of implicit returns, (I guess).

Attached is a screen shot of the javascript output compiled from the above coffeescript.

enter image description here

2 Answers 2

4

Every function that does work for async needs to take a callback as its only argument.

one = (callback) ->
  console.log "one"
  callback()

two = (callback) ->
  console.log "two"
  callback()

testFunction: () ->
  console.log "testFunction"
  async.series [one, two], (error) ->
    console.log "all done", error
Sign up to request clarification or add additional context in comments.

2 Comments

that is a very useful answer thanks. this is the point where i'm frustrated, have been looking at the docs for a bit now and it def wasn't clear that I needed to arrive at this. if you can't pass in arguments, how to give the functions inside the closures arguments ?
So the story is a bit more complicated, but I wanted to keep it simple. Technically you can use async.apply and take several arguments, but the last one is always the callback that tells async "I'm done".
3

You've got a number of problems. The first is that you're not passing the correct arguments to async.series. It expects:

async.series([functions...], callback)

while you're calling

async.series(function, function)

Since the length attribute of the first function is undefined, it assumes its an empty array and skips straight to the "callback" (second function). It sounds like you may want to pass an array of two functions and omit the callback.

The second problem is that functions passed to async.series must call a callback in order for progression to continue. The callback is the first argument to each function:

testFunction: () ->
  console.log "testFunction"
  async.series([
    ((next) ->
      console.log "first"
      next()
    ),
    ((next) -> 
      console.log "second"
      next()
    )
  ])

async ignores the return value of most (all?) functions that you pass to it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.