Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function A(){
- return new Promise(function(fulfill, reject){
- connection.query('SELECT * AS value FROM table_one', function(err, res){
- if(err){
- reject(err);
- }else{
- fulfill(res);
- }
- });
- });
- }
- function B(resultFromA){
- return new Promise(function(fulfill, reject){
- connection.query('SELECT * FROM something WHERE x = ' + resultFromA[0].value, function(err, res){
- if(err){
- reject(err);
- }else{
- fulfill(res);
- }
- });
- });
- }
- A().then(B, function(errorFromA){
- console.log("Error from A: " + errorFromA);
- }).then(function(resultFromB){
- console.log("Result from A: " + resultFromB);
- }, function(errorFromB){
- console.log("Error from B: " + errorFromB);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement