Skip to content

timeout should skip the timer if the delay is <= 0 #49

@lilyball

Description

@lilyball

If the delay is zero or negative, instead of running a timer we should immediately check if the promise is resolved, and if not then time it out. This avoids an unnecessary timer and possibly operation queue work.

Implementation note: We should hop on the context, then run the timeout block there. Don't check it synchronously. The timeout block already does what we want and verifies that the promise hasn't resolved yet.

Design note: The above is different than checking result immediately and timing out if not. In particular, if we're using a context other than immediate, if the promise's upstream has resolved and the propagation is pending on that context, it may resolve the given promise prior to the timeout block firing. This matches current behavior. We should document that if the user wants to do the equivalent of if promise.result == nil { timeout() } then they can pass the .immediate context, or the nowOr(_) context (see #34).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions