Answer the question
In order to leave comments, you need to log in
Mysql in node, async and shutdown?
Good day, gentlemen!
I'm trying to ride a recalcitrant asynchronous node.
Essence of the question:
There is a script that works and iterates in a loop, writes to the database at each iteration, exits and hangs because the connection to the database hangs, I don’t understand how to close the connection after the loop is completed. It cuts out all the time.
objectGame = [....]
number = objectGame.length
db.connect()
for game in objectGame
parserGame(game, getResultOneGame)
db.end()
objectGame = [....]
number = objectGame.length
for game in objectGame
number--
parserGame(game, getResultOneGame, number)
parserGame = ( ) ->
............
if namber ==1
db.end()
Answer the question
In order to leave comments, you need to log in
Judging by the description of the question, misunderstanding comes from ignorance of the language. The path is simple, learn.
Array.prototype.asyncEach = function (each, done) {
var i = -1, a = this
function iter() {
if (++i === a.length) { done && done(); return }
each.call(a, a[i], iter)
}
iter()
}
let objectGame = ["GTA", "CS", "OTHER"]
db.connect()
objectGame.asyncEach(function (item, next) {
parserGame(item, getResultOneGame)
next()
}, db.end)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question