mirror of
https://github.com/k3s-io/k3s.git
synced 2026-04-06 09:55:01 -04:00
Currently only waits on etcd and kine, as other components are stateless and do not need to shut down cleanly. Terminal but non-fatal errors now request shutdown via context cancellation, instead of just logging a fatal error. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
20 lines
423 B
Go
20 lines
423 B
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const DefaultContextDelay = 5 * time.Second
|
|
|
|
// DelayCancel returns a context that will be cancelled
|
|
// with a delay after the parent context has been cancelled.
|
|
func DelayCancel(ctx context.Context, delay time.Duration) context.Context {
|
|
dctx, dcancel := context.WithCancel(context.Background())
|
|
go func() {
|
|
<-ctx.Done()
|
|
time.Sleep(delay)
|
|
dcancel()
|
|
}()
|
|
return dctx
|
|
}
|