Skip to content

proposal: time: add cancellable func SleepC(context.Context, Duration) #76794

@sbalabanov

Description

@sbalabanov

What is the URL of the page with the issue?

N/A

What is your user agent?

N/A

Screenshot

No response

What did you do?

This is a feature request. time.Sleep() is a blocking call and cannot be cancelled. Add a helper to support context cancellation to help build more responsive tools.

What did you see happen?

N/A

What did you expect to see?

New function:

package time

func SleepC(ctx context.Context, d time.Duration) error {
    select {
    case <-ctx.Done():
        return ctx.Err()
    case <-time.After(d):
        return nil
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions