You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AbortSignal.timeout(...) method provided us with a nice functional mechanism to abort an operation after a given period of time and was quite a welcome addition. However, there is one use case that it currently does not quite adequately cover: idle timeouts. That is, given a long running operation, the ability to timeout only if there is not regular activity within a given period of time. If there is activity, the timeout resets.
For example, let's imagine that we have an async iterable like a ReadableStream. Once we start consuming the stream, we want to make sure that each read happens within about one second and that the stream is canceled if the reads do not occur fast enough. This would be difficult with AbortSignal.timeout(...) currently without being forced to create a new AbortSignal on every iteration, which seems wasteful. Instead, it would be nice to have a single AbortSignal timeout that can be reset.
const signal = AbortSignal.timeout(1000);
// do some work...
signal.update(); // reset the timer...
// do more work...
signal.update(); // reset the timer...
Obviously, however, this becomes a bit weird to have an update() method on AbortSignal instances created in other ways that does not do anything, so I'm not that worried about exactly what the api looks like... I'd mostly like to explore if this use case (specifically, allowing a single timeout-based AbortSignal to have it's timer reset) would be interesting.
The text was updated successfully, but these errors were encountered:
Perhaps, and is how I've addressed this previously, it just feels a bit... awkward. I mean, that same thing could have been said about AbortSignal.timeout() as well (and probably was, to be fair).
fetch() has some more detailed timer tracking issues for cases like this: whatwg/fetch#179 & whatwg/fetch#180. Perhaps they ought to be options for streams instead, interesting thought.
What is the issue with the DOM Standard?
The
AbortSignal.timeout(...)
method provided us with a nice functional mechanism to abort an operation after a given period of time and was quite a welcome addition. However, there is one use case that it currently does not quite adequately cover: idle timeouts. That is, given a long running operation, the ability to timeout only if there is not regular activity within a given period of time. If there is activity, the timeout resets.For example, let's imagine that we have an async iterable like a
ReadableStream
. Once we start consuming the stream, we want to make sure that each read happens within about one second and that the stream is canceled if the reads do not occur fast enough. This would be difficult withAbortSignal.timeout(...)
currently without being forced to create a newAbortSignal
on every iteration, which seems wasteful. Instead, it would be nice to have a singleAbortSignal
timeout that can be reset.Obviously, however, this becomes a bit weird to have an
update()
method onAbortSignal
instances created in other ways that does not do anything, so I'm not that worried about exactly what the api looks like... I'd mostly like to explore if this use case (specifically, allowing a single timeout-basedAbortSignal
to have it's timer reset) would be interesting.The text was updated successfully, but these errors were encountered: