Skip to content

Instantly share code, notes, and snippets.

@chuanxd
Created March 24, 2017 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuanxd/06edc613de6284fb896865971d0e4982 to your computer and use it in GitHub Desktop.
Save chuanxd/06edc613de6284fb896865971d0e4982 to your computer and use it in GitHub Desktop.
實做一個 promise finally
// http://bluebirdjs.com/docs/api/finally.html
Promise.prototype.end = function(fn) {
return new Promise((resolve, reject)=>{
this.then((res)=>{
fn(false, res)
resolve()
})
.catch((er)=>{
fn(true, er)
reject()
})
})
}
promise.end((err, res)=>{
if (err) {
// equal .catch
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment