-
Notifications
You must be signed in to change notification settings - Fork 662
fix(async): allow numbers greater than Number.MAX_SAFE_INTEGER in deadline
#6810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6810 +/- ##
=======================================
Coverage 94.10% 94.11%
=======================================
Files 581 581
Lines 42699 42700 +1
Branches 6790 6791 +1
=======================================
+ Hits 40184 40186 +2
+ Misses 2464 2463 -1
Partials 51 51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
allowInfinity option in deadlineallowInfinity option in deadline
|
If this adds support for Also, should |
|
I added it as an option because it could be considered a breaking change, and some people might expect the deadline to eventually be resolved in a finite amount of time. But personally I think it would make sense to just support it without the option As for the other question, I guess this could be iterated in another PR. But since the spec of AbortSignal.timeout only accepts until Number.MAX_SAFE_INTEGER, it might be tedious to implement maybe ? |
Changing throwing to non-throwing behavior typically isn't considered breaking (edit: I guess (?) that also means this wouldn't need to be marked unstable, as the interface wouldn't need to change at all).
It's true the actual use case for using values in
Using similar logic to const MAX_ABORT_TIMEOUT = Number.MAX_SAFE_INTEGER
function arbitraryLengthAbortSignalTimeout(delay: number): AbortSignal {
const ac = new AbortController();
// ensure non-negative integer (but > MAX_ABORT_TIMEOUT is OK, even if Infinity)
let currentDelay = delay = Math.trunc(Math.max(delay, 0) || 0);
const start = Date.now();
const queueTimeout = () => {
currentDelay = delay - (Date.now() - start);
if (currentDelay > MAX_ABORT_TIMEOUT) {
AbortSignal.timeout(MAX_ABORT_TIMEOUT).onabort = queueTimeout;
} else {
AbortSignal.timeout(Math.max(0, currentDelay)).onabort = function() {
ac.abort(this.reason);
};
}
};
queueTimeout();
return ac.signal;
} |
I mean it depends. Most CLI apps that supports a timeout option usually accepts specifying passing either
But then maybe it's actually useless to do, I mean, I currrently use |
Oh yeah, I guess implementing this would be thoroughly pointless haha. The equivalent max value for IMO either one of |
|
@lowlighter sorry for the delay in review! I like @lionel-rowe's suggestion. Never aborting when the timeout > I also think this can be landed as |
allowInfinity option in deadlineNumber.MAX_SAFE_INTEGER in deadline
Number.MAX_SAFE_INTEGER in deadlineNumber.MAX_SAFE_INTEGER in deadline
|
Sorry for the long delay, I've made the requested changes |
| * @param p The promise to make rejectable. | ||
| * @param ms Duration in milliseconds for when the promise should time out. | ||
| * @param ms Duration in milliseconds for when the promise should time out. If | ||
| * greater than `Number.MAX_SAFE_INTEGER`, the deadline will never expire. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
kt3k
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for updating!
This add a new
allowInfinity?: boolean;option to deadline to allowInfinityvalue.Why is this needed ?
deadline/abortabledoesn't have the same signature, so you can just interchange them inlinedeadlineAbortSignal.timeout()only support finite values, so usingInfinitywould throw an error (current behaviour)Infinitydeadline makes senses concept-wise, it's just an edge case