-
Notifications
You must be signed in to change notification settings - Fork 658
feat(async/unstable): support allowInfinity
option 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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6810 +/- ##
=======================================
Coverage 94.23% 94.23%
=======================================
Files 590 591 +1
Lines 42811 42823 +12
Branches 6788 6790 +2
=======================================
+ Hits 40341 40354 +13
+ Misses 2420 2419 -1
Partials 50 50 ☔ 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 |
This add a new
allowInfinity?: boolean;
option to deadline to allowInfinity
value.Why is this needed ?
deadline
/abortable
doesn't have the same signature, so you can just interchange them inlinedeadline
AbortSignal.timeout()
only support finite values, so usingInfinity
would throw an error (current behaviour)Infinity
deadline makes senses concept-wise, it's just an edge case