Skip to content

[Feature Request] Allow cancel polling of client.result() (via timeout / AbortSignal) to stop leak #1682

Closed
@alex-statsig

Description

@alex-statsig

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions