Skip to content

Instantly share code, notes, and snippets.

@SuoXC
Created August 7, 2018 12:36
Show Gist options
  • Select an option

  • Save SuoXC/016a3e2afabd59074eacd1c06ad3f151 to your computer and use it in GitHub Desktop.

Select an option

Save SuoXC/016a3e2afabd59074eacd1c06ad3f151 to your computer and use it in GitHub Desktop.
api demo wrapper with promise
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