Skip to content

Commit 6abc074

Browse files
authored
perf(NODE-6127): move error construction into setTimeout callback (#4094)
1 parent 3598c23 commit 6abc074

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/timeout.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class Timeout extends Promise<never> {
3333
return 'MongoDBTimeout';
3434
}
3535

36-
private timeoutError: TimeoutError;
3736
private id?: NodeJS.Timeout;
3837

3938
public readonly start: number;
@@ -55,17 +54,14 @@ export class Timeout extends Promise<never> {
5554
executor(noop, promiseReject);
5655
});
5756

58-
// NOTE: Construct timeout error at point of Timeout instantiation to preserve stack traces
59-
this.timeoutError = new TimeoutError(`Expired after ${duration}ms`);
60-
6157
this.duration = duration;
6258
this.start = Math.trunc(performance.now());
6359

6460
if (this.duration > 0) {
6561
this.id = setTimeout(() => {
6662
this.ended = Math.trunc(performance.now());
6763
this.timedOut = true;
68-
reject(this.timeoutError);
64+
reject(new TimeoutError(`Expired after ${duration}ms`));
6965
}, this.duration);
7066
// Ensure we do not keep the Node.js event loop running
7167
if (typeof this.id.unref === 'function') {

0 commit comments

Comments
 (0)