Created
December 27, 2016 01:49
-
-
Save mzbac/4ac73b1e87d2b58d5aed3bcdc8df7200 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'); | |
| 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