Created
August 7, 2018 12:36
-
-
Save SuoXC/016a3e2afabd59074eacd1c06ad3f151 to your computer and use it in GitHub Desktop.
api demo wrapper with promise
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
| function api(url){ | |
| return new Promise( | |
| function(resolve,reject){ | |
| setTimeout(function(){ | |
| resolve("request url finished:" + url) | |
| // reject("request url finished:" + url) | |
| },1000) | |
| } | |
| ) | |
| } | |
| c = api('hello') | |
| .then(function(data){console.log(data); return api('world')}) | |
| .then(console.log) | |
| .catch(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment