vendor/golang.org/x/net/context/go17.go
changeset 262 8d3354485fc3
parent 260 445e01aede7e
equal deleted inserted replaced
261:270cc4dda0c5 262:8d3354485fc3
    30 //
    30 //
    31 // Canceling this context releases resources associated with it, so code should
    31 // Canceling this context releases resources associated with it, so code should
    32 // call cancel as soon as the operations running in this Context complete.
    32 // call cancel as soon as the operations running in this Context complete.
    33 func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
    33 func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
    34 	ctx, f := context.WithCancel(parent)
    34 	ctx, f := context.WithCancel(parent)
    35 	return ctx, CancelFunc(f)
    35 	return ctx, f
    36 }
    36 }
    37 
    37 
    38 // WithDeadline returns a copy of the parent context with the deadline adjusted
    38 // WithDeadline returns a copy of the parent context with the deadline adjusted
    39 // to be no later than d. If the parent's deadline is already earlier than d,
    39 // to be no later than d. If the parent's deadline is already earlier than d,
    40 // WithDeadline(parent, d) is semantically equivalent to parent. The returned
    40 // WithDeadline(parent, d) is semantically equivalent to parent. The returned
    44 //
    44 //
    45 // Canceling this context releases resources associated with it, so code should
    45 // Canceling this context releases resources associated with it, so code should
    46 // call cancel as soon as the operations running in this Context complete.
    46 // call cancel as soon as the operations running in this Context complete.
    47 func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
    47 func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
    48 	ctx, f := context.WithDeadline(parent, deadline)
    48 	ctx, f := context.WithDeadline(parent, deadline)
    49 	return ctx, CancelFunc(f)
    49 	return ctx, f
    50 }
    50 }
    51 
    51 
    52 // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
    52 // WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
    53 //
    53 //
    54 // Canceling this context releases resources associated with it, so code should
    54 // Canceling this context releases resources associated with it, so code should