Skip to content

Commit

Permalink
changed timeout to pre-generate a stack - in the case of a timeout, t…
Browse files Browse the repository at this point in the history
…he stack will have a context to the operation that failed
  • Loading branch information
aricart committed Sep 13, 2021
1 parent af2b850 commit 57dfd73
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nats-base-client/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export interface Timeout<T> extends Promise<T> {
}

export function timeout<T>(ms: number): Timeout<T> {
// by generating the stack here to help identify what timed out
const err = NatsError.errorForCode(ErrorCode.Timeout);
let methods;
let timer: number;
const p = new Promise((_resolve, reject) => {
Expand All @@ -93,7 +95,7 @@ export function timeout<T>(ms: number): Timeout<T> {
methods = { cancel };
// @ts-ignore: node is not a number
timer = setTimeout(() => {
reject(NatsError.errorForCode(ErrorCode.Timeout));
reject(err);
}, ms);
});
// noinspection JSUnusedAssignment
Expand Down

0 comments on commit 57dfd73

Please sign in to comment.