title: Expecting Sequelize transaction to wait for callback function
body: <p>Here I am working with Nodejs and Mysql. And using Sequelize module as ORM.
  And I am Using transactions for my need and Inside transactions I need to call another api and based on response I have to proceed further or commit the transactions. <strong>Problem is transaction not waiting for API response</strong>. Here I am adding some code snippets...</p>
  
  <pre><code>var errorcheck = true;
  models.sequelize.transaction().then( function ( t ) {}).then( function () {
      return models.Task.find( {
          where: { "id": 1 },
          include: [{
              model: models.Evaluation,
              include : [
                  {
                      model: models.EvalForm,
                      attributes : ['id','name']
                  },
                  {
                      model: models.Clarification,
                      attributes : ['id','status']
                  }
              ]
          },{
              model: models.User,
              include: [{
                  model : models.User,
                  as: 'Manager',
                  attributes : ["id","ManagerId","name"],
                  include : [{
                      model : models.User,
                      as: 'Manager',
                      attributes : ["id","ManagerId","name"]
                  }]
              }]
          }]
      }).then(function(task) {
          // new API
          client.post('api/saveEval/', finalevalObj, function(err, httpResponse, body) {
              if(body.resCode==="OK"){
                  return finaltaskobj.Evaluation.updateAttributes(finalevalUpObj, { transaction: t }).then(function (data2) {
  
                  }).catch(function (err) { errorcheck = false; return res.send({ "error": { "code": 5000, "message": err.message } }) });
              }else{
                  errorcheck = false;
                  errors.push(body.msg);
              }
          });
  
  
      }).then(function ( definitions ) {
          if(errorcheck){
              return t.commit();
          }else{
              return t.rollback()
          };
      });
  }).then( function () {
      if(errorcheck){
         //Now Here I am calling new API. And working fine. I know this is not better way of doing.
         return res.send({"resCode":"OK"});   
      }else{
          return res.send({"resCode":"ERROR"});
      };
  }, function (err) {
      return res.send({"error":{"code": 5000,"message": err.message}});
  });
  </code></pre>
  
  <p>Like this I have so many updates before and after calling new API. But transaction commits before getting response from new API. I understood I have to do something to wait  transaction. Some where I am using "models.sequelize.Promise.map" for iteration purpose and working fine. Do I have any other method like that. Please help me by improving same code. </p>
  
  <p>Thanks for great help......</p>