createTaskWithTimeout: Don't log expiration if task threw (#1412)
FREEBIE
This commit is contained in:
parent
3f7fbd93d5
commit
46b64e306f
3 changed files with 30 additions and 4 deletions
|
@ -40272,7 +40272,13 @@ libsignal.ProvisioningCipher = function() {
|
|||
return reject(error);
|
||||
};
|
||||
|
||||
var promise = task();
|
||||
var promise;
|
||||
try {
|
||||
promise = task();
|
||||
} catch(error) {
|
||||
clearTimer();
|
||||
throw error;
|
||||
}
|
||||
if (!promise || !promise.then) {
|
||||
clearTimer();
|
||||
complete = true;
|
||||
|
|
|
@ -51,7 +51,13 @@
|
|||
return reject(error);
|
||||
};
|
||||
|
||||
var promise = task();
|
||||
var promise;
|
||||
try {
|
||||
promise = task();
|
||||
} catch(error) {
|
||||
clearTimer();
|
||||
throw error;
|
||||
}
|
||||
if (!promise || !promise.then) {
|
||||
clearTimer();
|
||||
complete = true;
|
||||
|
|
|
@ -22,13 +22,13 @@ describe('createTaskWithTimeout', function() {
|
|||
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 complete = false;
|
||||
var task = function() {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
completed = true;
|
||||
complete = true;
|
||||
resolve();
|
||||
}, 3000);
|
||||
});
|
||||
|
@ -57,4 +57,18 @@ describe('createTaskWithTimeout', function() {
|
|||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue