Created
May 14, 2014 23:07
-
-
Save azu/a5b93bb0a91fa873e64c to your computer and use it in GitHub Desktop.
use reject not thorw
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
"use strict"; | |
var TimeoutError = require("./TimeoutError").TimeoutError; | |
var delayPromise = require("./delayPromise").delayPromise; | |
function timeoutPromise(promise, ms) { | |
var timeout = new Promise(function (resolve, reject) { | |
return delayPromise(ms).then(function () { | |
reject(new TimeoutError("Operation timed out after " + ms + " ms")); | |
}) | |
}); | |
return Promise.race([promise, timeout]); | |
} | |
module.exports.timeoutPromise = timeoutPromise; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment