I have the below async code.
for fileName in sourceFiles
console.log 'dealing with ', fileName
async.waterfall [
(callback) ->
console.log "going to read ", fileName
fs.readFile fileName, (err, content) ->
if err then throw err
callback null, fileName, content
return
(fileName, content, callback) ->
console.log 'length of: ', fileName, ' is: ', content.length
I expected that the output will be something like:
dealing with file1
going to read file1
length of file1 is 10
dealing with file2
going to read file2
length of file 2 is 20
instead, what I get is this:
dealing with file1
dealing with file2
going to read file2
going to read file2 <- note it is the same file repeated
length of file2 is 20
length of file2 is 20
I'm not able to figure out why this would be so. (This being a coffeescript is no issue. It is the same output in JS too)