Documentation ¶
Index ¶
- Constants
- func Advance(ctx context.Context) error
- func After(ctx context.Context, deadline int64, epoch int64) (int, <-chan Completion)
- func Cancel(ctx context.Context, id int) <-chan Completion
- func CancelTimer(ctx context.Context, id int) error
- func EnsureTickInContext(ctx context.Context) context.Context
- func InitTimestamp(name string, opts ...grpc.DialOption) error
- func OutsideTime(ctx context.Context) context.Context
- func Reset(ctx context.Context) error
- func SetPolicy(ctx context.Context, policy pb.StepperPolicy, delay *dpb.Duration, match int64) (*pb.StatusResponse, error)
- func StartTimer(ctx context.Context, delay int64, msg interface{}, ...) (int, error)
- func Status(ctx context.Context) (*pb.StatusResponse, error)
- func Tick(ctx context.Context) int64
- type Completion
- type Listener
- type Ticker
Constants ¶
const ( NoEpochCheck = math.MaxInt64 InvalidId = -1 )
Variables ¶
This section is empty.
Functions ¶
func After ¶
After delays execution until the simulated time meets or exceeds the specified deadline. Completion is asynchronous, even if no delay is required.
func Cancel ¶
func Cancel(ctx context.Context, id int) <-chan Completion
Cancel attempts to terminate an outstanding After call. If the instance is found, then it will complete with a 'timer canceled' error. The Cancel operation's completion channel receives notification once the After call is either not found or canceled.
func CancelTimer ¶
CancelTimer removes the designated waiting timer.
func EnsureTickInContext ¶
EnsureTickInContext checks if a simulated time tick is already present in the context. If not, it stores the current simulated time.
func InitTimestamp ¶
func InitTimestamp(name string, opts ...grpc.DialOption) error
InitTimestamp stores the information needed to be able to connect to the Stepper service.
func OutsideTime ¶
OutsideTime forces the simulated time tick in the context to be '-1', which is the designator for an operation that is outside the simulated time flow.
func Reset ¶
Reset the simulated time back to its starting state, including reverting all policies back to their default. This is used by unit tests to ensure a well known starting state for a test.
func SetPolicy ¶
func SetPolicy( ctx context.Context, policy pb.StepperPolicy, delay *dpb.Duration, match int64) (*pb.StatusResponse, error)
SetPolicy sets the stepper policy
func StartTimer ¶
func StartTimer( ctx context.Context, delay int64, msg interface{}, callback func(msg interface{})) (int, error)
StartTimer creates a new timer that operates in simulated time. The delay parameter specifies the number of ticks to wait until the timer expires. At that point, the supplied msg is sent on the completion channel specified by the parameter ch. This function returns an id that can be used to cancel the timer, and an error to indicate if the timer was successfully set.
Types ¶
type Completion ¶
type Completion struct { Status *pb.StatusResponse Err error }
Completion contains the final result of the registered event notification. It is either an updated status, or an error that arose during processing.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener defines the data associated with a running instance.
func NewListener ¶
func NewListener(ep string, dialOpts ...grpc.DialOption) *Listener
NewListener creates and returns a new Listener instance, with the background goroutine initialized and running.
func (*Listener) After ¶
After requests a notification once the simulated time has passed the dueTime value. It returns the unique ID, that can be used to cancel the request, the channel to listen for the notification event, and an error, if the request could not be added.
func (*Listener) Cancel ¶
func (l *Listener) Cancel(id int) (chan Completion, error)
Cancel attempts to cancel an outstanding notification request. The id specifies the request to cancel. It returns a channel to listen to for confirmation of the cancellation, and an error that indicates if the cancel request was accepted. If the error value is nil, then the returned channel will receive a confirmation message once either the specified id is not found, or it is successfully canceled.
func (*Listener) Stop ¶
func (l *Listener) Stop()
Stop is a function that terminates the background activities of the listener, and marks the listener as closed, so as to prevent future requests to it.
func (*Listener) UpdateStatus ¶
func (l *Listener) UpdateStatus(status *pb.StatusResponse)
UpdateStatus is a function that posts an update to the simulated time status. It proceeds returns once the status has been successfully updated.
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
Ticker is a mechanism that continuously requests notification of the next simulated tick, until it is ordered to stop.