Skip to content

Commit

Permalink
allow for negative duration Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Jul 29, 2024
1 parent 5505c68 commit 5fc6471
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { clearTimeout, setTimeout } from 'timers';

import { MongoOperationTimeoutError, MongoRuntimeError } from './error';
import { MongoRuntimeError } from './error';
import { noop } from './utils';

/** @internal */
Expand Down Expand Up @@ -260,15 +260,13 @@ export class CSOTTimeoutContext extends TimeoutContext {
get timeoutForSocketWrite(): Timeout | null {
const { remainingTimeMS } = this;
if (!Number.isFinite(remainingTimeMS)) return null;
if (remainingTimeMS > 0) return Timeout.expires(remainingTimeMS);
throw new MongoOperationTimeoutError('Timed out before socket write');
return Timeout.expires(remainingTimeMS);
}

get timeoutForSocketRead(): Timeout | null {
const { remainingTimeMS } = this;
if (!Number.isFinite(remainingTimeMS)) return null;
if (remainingTimeMS > 0) return Timeout.expires(remainingTimeMS);
throw new MongoOperationTimeoutError('Timed out before socket read');
return Timeout.expires(remainingTimeMS);
}
}

Expand Down

0 comments on commit 5fc6471

Please sign in to comment.