Skip to content

Instantly share code, notes, and snippets.

@mzbac
Created December 27, 2016 01:49
Show Gist options
  • Select an option

  • Save mzbac/4ac73b1e87d2b58d5aed3bcdc8df7200 to your computer and use it in GitHub Desktop.

Select an option

Save mzbac/4ac73b1e87d2b58d5aed3bcdc8df7200 to your computer and use it in GitHub Desktop.
var Promise = require('bluebird');
function request() {
return new Promise(function (resovle, reject) {
setTimeout(function() {
var num = Math.random();
if(num > 0.8){
resovle(num);
}else{
reject(num);
}
},1000);
})
}
function digui() {
return request().then(function(res) {
console.log('成功 ' + res);
return;
}).catch(function(err) {
console.log('失败 ' + err);
return digui();
})
}
digui().done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment