createTaskWithTimeout: Don't log expiration if task threw (#1412)

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-08-30 13:33:55 -07:00 committed by GitHub
parent 3f7fbd93d5
commit 46b64e306f
3 changed files with 30 additions and 4 deletions

View file

@ -40272,7 +40272,13 @@ libsignal.ProvisioningCipher = function() {
return reject(error); return reject(error);
}; };
var promise = task(); var promise;
try {
promise = task();
} catch(error) {
clearTimer();
throw error;
}
if (!promise || !promise.then) { if (!promise || !promise.then) {
clearTimer(); clearTimer();
complete = true; complete = true;

View file

@ -51,7 +51,13 @@
return reject(error); return reject(error);
}; };
var promise = task(); var promise;
try {
promise = task();
} catch(error) {
clearTimer();
throw error;
}
if (!promise || !promise.then) { if (!promise || !promise.then) {
clearTimer(); clearTimer();
complete = true; complete = true;

View file

@ -22,13 +22,13 @@ describe('createTaskWithTimeout', function() {
assert.strictEqual(error, flowedError); assert.strictEqual(error, flowedError);
}); });
}); });
it('rejects if promise takes too long', function() { it('rejects if promise takes too long (this one logs error to console)', function() {
var error = new Error('original'); var error = new Error('original');
var complete = false; var complete = false;
var task = function() { var task = function() {
return new Promise(function(resolve) { return new Promise(function(resolve) {
setTimeout(function() { setTimeout(function() {
completed = true; complete = true;
resolve(); resolve();
}, 3000); }, 3000);
}); });
@ -57,4 +57,18 @@ describe('createTaskWithTimeout', function() {
assert.strictEqual(result, 'hi!') assert.strictEqual(result, 'hi!')
}); });
}); });
it('rejects if task throws (and does not log about taking too long)', function() {
var error = new Error('Task is throwing!');
var task = function() {
throw error;
};
var taskWithTimeout = textsecure.createTaskWithTimeout(task, this.name, {
timeout: 10
});
return taskWithTimeout().then(function(result) {
throw new Error('Overall task should reject!')
}, function(flowedError) {
assert.strictEqual(flowedError, error);
});
});
}); });