A
A
Axepec2017-04-14 00:34:00
MySQL
Axepec, 2017-04-14 00:34:00

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()

I tried to do this, but it doesn't work...
objectGame = [....]
  number = objectGame.length

  for game in objectGame
     number--
     parserGame(game, getResultOneGame, number)

parserGame = ( ) ->
   ............
   if namber ==1 
      db.end()

+ the upcoming problem, it is necessary that the script run independently once a day. For the first time I delve into the documentation and configuration of the VPN server, so I ask for advice on how to do it better, run the node and let it run on time, via setTimeout, or somehow better set up on the server, scheduled file launch

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2017-04-14
@vshvydky

Judging by the description of the question, misunderstanding comes from ignorance of the language. The path is simple, learn.

L
Leo Developer, 2017-04-14
@crazy_leo

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 question

Ask a Question

731 491 924 answers to any question