Created
December 27, 2017 17:24
-
-
Save KhalilZaidoun/48b1c7175910e33efa1f280a114a875b to your computer and use it in GitHub Desktop.
Timeout Promise wrapper
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
// Timeout Promise wrapper | |
export default function timeoutPromise(timeout, err, promise) { | |
return new Promise(function(resolve,reject) { | |
promise.then(resolve,reject); | |
setTimeout(reject.bind(null,err), timeout); | |
}); | |
} | |
/* | |
timeoutPromise(100, new Error('Timed Out!'), fetcn(...)) | |
.then(...) | |
.catch(...) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment