var DEFAULT_TIMEOUT = 5000;
var TimedPromise = function(timeoutAfter) {
var _self = this;
var _rejectFunc; var _resolveFunc;
var _timeoutMs = timeoutAfter ? timeoutAfter : DEFAULT_TIMEOUT;
var _promise = new Promise(function(resolveFunc, rejectFunc) { _resolveFunc = resolveFunc.bind(this); _rejectFunc = rejectFunc.bind(this); });
var _timeout = setTimeout(function() {
if (_rejectFunc) { _rejectFunc(Error('timeout')); } else {
_promise.then = function() { return Promise.reject(new Error('timeout')); }; } }, _timeoutMs );
_self.resolve = function(arg) {
if (_timeout) { clearTimeout(_timeout); }
_resolveFunc(arg); };
_self.reject = function(arg) {
if (_timeout) { clearTimeout(_timeout); }
_rejectFunc(arg); };
_self.promise = function() { return _promise; };
};
exports = module.exports = TimedPromise;--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/4c1b478c-b2ff-453d-b35d-d5a4de967af2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAJkwh4Kg%3D3HayO_Dkh1SHSpa2SncY7JN4QzuKMacJBHPBXgE5Q%40mail.gmail.com.
Promise.race((new TimedPromise(1000)).promise(), someLibCall()]).then(...);