Answer the question
In order to leave comments, you need to log in
Async in node.js, eachOfSeries synchronous loop, or doing only one iteration?
Good day, professors.
I'm new to node, I'm trying to make a synchronous loop in node. async library.
Hangs after the first iteration. Example:
res = [
'textFile/file_1.txt' # ООООЧень большой
'textFile/file_2.txt' # маленький
'textFile/file_3.txt' # ооочень маленький
]
funRead = (file, i) ->
fs.readFile file, 'utf8', (err, contents) ->
console.log i + ') i am read ->> ' + file
async.eachOfSeries res, ((item, i) ->
funRead(item, i)
), ->
console.log 'testCB'
async.eachOf
the result naturally like this: async.series [
funRead1 = () ->
fs.readFile 'textFile/file_1.txt', 'utf8', (err, contents) ->
console.log '1) i am read ->> textFile/file_1.txt'
funRead2 = () ->
fs.readFile 'textFile/file_2.txt', 'utf8', (err, contents) ->
console.log '2) i am read ->> textFile/file_2.txt'
funRead3 = () ->
fs.readFile 'textFile/file_3.txt', 'utf8', (err, contents) ->
console.log '3) i am read ->> textFile/file_3.txt'
], () ->
console.log 'test CB'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question