Created
August 11, 2015 14:16
-
-
Save LookOnTheBrightSide/182d8518e4bc177b3730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.multiply = function (number, cb){ | |
setTimeout(function(){ | |
var result = number * 7; | |
//console.log( number * 7) | |
if (number == 6){ | |
return cb("6 is not allowed", null) | |
} | |
cb(null, result); | |
},1000); | |
} | |
exports.manualMultiply = function(){ | |
/* | |
return new Promise(function (resolve, reject) { | |
var xhr = new XMLHttpRequest; | |
xhr.addEventListener("error", reject); | |
xhr.addEventListener("load", resolve); | |
xhr.open("GET", url); | |
xhr.send(null); | |
}); | |
*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require("bluebird"); | |
var multiply = Promise.promisifyAll(require('./multiply-promise')); | |
/* | |
multiply.multiplyAsync(9) | |
.then(function(result){ | |
console.log('----'); | |
console.log(result); | |
}).then(function(){ | |
console.log('bye, bye!') | |
}); | |
*/ | |
Promise.join(multiply.multiplyAsync(9), | |
multiply.multiplyAsync(7), | |
multiply.multiplyAsync(6), | |
multiply.multiplyAsync(3), | |
function(nine, seven, three){ | |
console.log(nine); | |
console.log(seven); | |
console.log(three); | |
}).error(function(err){ | |
console.log(err) | |
});; | |
/* | |
multiply.multiply(6, function(err, result){ | |
if (err){ | |
return console.log(err) | |
} | |
console.log(result); | |
}); | |
*/ | |
/* | |
multiply(9) | |
.then(function(result){ | |
console.log(result); | |
}) | |
.error(function(err){ | |
return console.log(err) | |
}); | |
join(multiply(9), multiply(7), function(nine, seven){ | |
console.log(nine * seven); | |
}); | |
*/ | |
console.log('bye'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment