I am lost in the callbacks. code and desired output is below. So what happening is inner loop is not executed that should prints the @b array=> ['a','b','c']
Async = require('async')
@a = [1,2,3]
@b = ['a','b','c']
Async.forEachSeries @a, (aa , cbLoop1) =>
console.log aa
console.log "^ number from Loop-1"
Async.forEachSeries @b, (bb , cbLoop2) =>
#call the method below
Async.waterfall(
[
(cb) ->
#call method 'start'
#'start' method has a callback that gets info using HTTP GET
start bb , (error , response) ->
#console.log(response) or do something with response
cbLoop2()
]
)
cbLoop1()
# Desired OUTPUT
1
^ number from Loop-1
a
b
c
2
^ number from Loop-1
a
b
c
3
^ number from Loop-1
a
b
c
*David answer helped me. I was trying get hold of Async forSeries and waterfall syntax. *any inputs to improve are welcome !
async.waterfall
takes a 2nd argument: "An optional callback to run once all the functions have completed". It's unclear from your question if this breaks the flow you are trying to achieve, but could you just callcbLoop2()
as the 2nd argument towaterfall
instead of calling it at the end of the first task? A simplified example: