Skip to content

Commit

Permalink
clear the error if cancelled, limit stack trace size otherwise to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Aug 30, 2023
1 parent 63d400d commit 93814d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ function timeoutHandle(e, deferred, overloadSafe) {
Q.timeout = function (promise, ms, message = undefined, overloadSafe = true) {
const deferred = Q.defer()

const e = new Error(message ? message : `Timed out after ${ms} ms`)
const stackTraceLimit = Error.stackTraceLimit
Error.stackTraceLimit = 10
let e = new Error(message ? message : `Timed out after ${ms} ms`)
Error.stackTraceLimit = stackTraceLimit

let timeout

promise.then(deferred.resolve, deferred.reject).then(() => {
Expand All @@ -235,6 +239,7 @@ Q.timeout = function (promise, ms, message = undefined, overloadSafe = true) {
try {
if (promise.cancel) promise.cancel()
} finally {
e = null
deferred.reject(new CancellationError())
clearTimeout(timeout)
}
Expand Down

0 comments on commit 93814d2

Please sign in to comment.