Skip to content

Commit

Permalink
Merge branch 'feature/timeout-fixes' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
etki committed Aug 14, 2017
2 parents 45aefa4 + 8aaabb3 commit 63463db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/concurrent/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ TimeoutException.prototype.constructor = TimeoutException

/**
* @param {Promise.<*>|Thenable.<*>} promise Promise to add time bound to
* @param {int} timeout Timeout in milliseconds
* @param {string} message
* @param {int} [timeout] Timeout in milliseconds
* @param {string} [message]
* @return {Thenable.<*>}
*/
function timeout (promise, timeout, message) {
if (timeout < 0) {
if (typeof timeout !== 'number' || timeout < 0) {
return promise
}
return new Promise(function (resolve, reject) {
Expand Down
10 changes: 10 additions & 0 deletions test/suites/integration/concurrent/timeout.timeout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ describe('Integration', function () {
return expect(timeout(promise, -1)).to.equal(promise)
})

it('returns promise if timeout is omitted', function () {
var promise = new Promise(function () {})
return expect(timeout(promise)).to.equal(promise)
})

it('returns promise if not-a-number is supplied', function () {
var promise = new Promise(function () {})
return expect(timeout(promise, false)).to.equal(promise)
})

it('wraps promise in timed out one', function () {
var promise = new Promise(function () {})
var wrapped = timeout(promise, 0)
Expand Down

0 comments on commit 63463db

Please sign in to comment.