Files
kubesphere/vendor/github.com/open-policy-agent/opa/topdown/cancel.go
hongming 9769357005 update
Signed-off-by: hongming <talonwan@yunify.com>
2020-03-20 02:16:11 +08:00

34 lines
641 B
Go

// Copyright 2017 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package topdown
import (
"sync/atomic"
)
// Cancel defines the interface for cancelling topdown queries. Cancel
// operations are thread-safe and idempotent.
type Cancel interface {
Cancel()
Cancelled() bool
}
type cancel struct {
flag int32
}
// NewCancel returns a new Cancel object.
func NewCancel() Cancel {
return &cancel{}
}
func (c *cancel) Cancel() {
atomic.StoreInt32(&c.flag, 1)
}
func (c *cancel) Cancelled() bool {
return atomic.LoadInt32(&c.flag) != 0
}