Skip to content

Instantly share code, notes, and snippets.

@LookOnTheBrightSide
Created August 11, 2015 14:16
Show Gist options
  • Save LookOnTheBrightSide/182d8518e4bc177b3730 to your computer and use it in GitHub Desktop.
Save LookOnTheBrightSide/182d8518e4bc177b3730 to your computer and use it in GitHub Desktop.
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);
});
*/
}
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