Advertisement
Guest User

Untitled

a guest
Feb 19th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function A(){
  2.     return new Promise(function(fulfill, reject){
  3.         connection.query('SELECT * AS value FROM table_one', function(err, res){
  4.             if(err){
  5.                 reject(err);
  6.             }else{
  7.                 fulfill(res);
  8.             }
  9.         });
  10.     });
  11. }
  12.  
  13. function B(resultFromA){
  14.     return new Promise(function(fulfill, reject){
  15.         connection.query('SELECT * FROM something WHERE x = ' + resultFromA[0].value, function(err, res){
  16.             if(err){
  17.                 reject(err);
  18.             }else{
  19.                 fulfill(res);
  20.             }
  21.         });
  22.     });
  23. }
  24.  
  25. A().then(B, function(errorFromA){
  26.     console.log("Error from A: " + errorFromA);
  27. }).then(function(resultFromB){
  28.     console.log("Result from A: " + resultFromB);
  29. }, function(errorFromB){
  30.     console.log("Error from B: " + errorFromB);
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement