You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/lib/stop_context.go

41 lines
802 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package lib
import (
"context"
"time"
)
// StopChannelContext implements the context.Context interface
// You provide the channel to select on to determine whether
// the context should be canceled and other code such
// as the rate.Limiter will automatically use the channel
// appropriately
type StopChannelContext struct {
StopCh <-chan struct{}
}
func (c *StopChannelContext) Deadline() (deadline time.Time, ok bool) {
ok = false
return
}
func (c *StopChannelContext) Done() <-chan struct{} {
return c.StopCh
}
func (c *StopChannelContext) Err() error {
select {
case <-c.StopCh:
return context.Canceled
default:
return nil
}
}
func (c *StopChannelContext) Value(key interface{}) interface{} {
return nil
}