I would like synchronous results.
All I want'll want to enter data by dividing 5000 by one.
However, as a result of asynchronous listed it is struggling.
I want to see as a result of synchronous languages such as java.
I want these results:
100-elements
commit
100-elements
commit
100-elements
commit
100-elements
commit
However, the code currently gets these results:
100-elements
100-elements
100-elements
100-elements
100-elements
.
.
.
.
100-elements
commit
commit
commit
commit
commit
commit
commit
.
.
.
.
commit
How can I get these results? Please help me. Thank you.
mysql.getConnection(function(err, connection){
  if(err){ connection.release(); return; }
  var array = [];
  var count = 300000;
  var length = count;
  for(var i=0; i<count; i++){
    (function(currentI, master){
      process.nextTick(function(){
        array.push([currentI, master]);
        if(currentI % 5000 === 0){
          console.log('100-elements');
          array = [];
          connection.beginTransaction(function(err){
            if(err){
              throw err;
            }
            var query = "insert into users(username, password) values ?";
            connection.query(query, [array], function (err, rows) {
              if (!err) {
                //commit start
                connection.commit(function(){
                  if (err) {
                    console.error(err);
                    connection.rollback(function () {
                      console.error('rollback error');
                      throw err;
                    });
                  } else {
                    console.log("Commit");
                  }/ / if err
                    }); //commit end
                } else {
                                  console.log(err);
                connection.rollback(function(){
                  throw err;
                });
              } // if
            }) // cnnection query
          }); // beginTransaction
        } //if
      });
    }(i, 'master'));
  } //for
}) // getConnection