Description
Is your feature request related to a problem? Please describe.
Currently if you create a run and want to observe the result, the most straightforward approach is to call await handle.result()
which uses await client.result(...)
. Sometimes you may want to attempt to get the result but not wait forever for the run to finish (the run may have a large timeout, and you just want to attempt to wait for it briefly). However, the current implementation of handle.result()
/ client.result()
provides no mechanism to cancel the awaiting. The function seems to trigger an infinite loop here, which will continue polling until the job is completed. This is a leak that can't be cleaned up by the caller (and likely the caller's scope will leak in any promise handlers, even with use of something like Promise.race
).
Describe the solution you'd like
The result()
functions should accept an AbortSignal
(or a timeout, but AbortSignal
is maybe a better generalization) to allow for cancellation of the polling. Then the caller may do something like await handle.result({signal: AbortSignal.timeout(10000)})
to wait up to 10s for the job completion (even if the job has a much longer timeout like 1 hour)
Additional context
I believe a manual polling of the run status could work around this, but the .result()
function provides much more convenience around following dependent runs. I think it would be valuable and fairly straightforward to just build this support in natively.