Skip to content

Instantly share code, notes, and snippets.

@azu
Created May 14, 2014 23:07
Show Gist options
  • Save azu/a5b93bb0a91fa873e64c to your computer and use it in GitHub Desktop.
Save azu/a5b93bb0a91fa873e64c to your computer and use it in GitHub Desktop.
use reject not thorw
"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