Last active
November 29, 2016 20:19
-
-
Save Fenchurchh/8a7a21e8616716e13e3a997fcef89568 to your computer and use it in GitHub Desktop.
This file contains 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
const exec = require("promised-exec") | |
function onFailure(err) { | |
console.log("err", err) | |
} | |
function onSuccess(response) { | |
console.log("success", response) | |
} | |
/** | |
* timedPromise(duration)(promise) returns promise that rejects after duration ms | |
*/ | |
let timedPromise = duration => fx => new Promise((fulfill, reject) => { | |
let timer = setTimeout(t => { | |
reject("Request took longer than the timeout of " + duration + " ms") | |
}, duration) | |
let promise = fx.then(response => { | |
fulfill(response) | |
clearTimeout(timer) | |
}) | |
}) | |
timedPromise(1000)(exec("ll")) | |
.then(onSuccess) | |
.catch(onFailure) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment