Skip to content

Instantly share code, notes, and snippets.

@KhalilZaidoun
Created December 27, 2017 17:24
Show Gist options
  • Save KhalilZaidoun/48b1c7175910e33efa1f280a114a875b to your computer and use it in GitHub Desktop.
Save KhalilZaidoun/48b1c7175910e33efa1f280a114a875b to your computer and use it in GitHub Desktop.
Timeout Promise wrapper
// 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