timestamp

package
v0.0.0-...-3e52749 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoEpochCheck = math.MaxInt64
	InvalidId    = -1
)

Variables

This section is empty.

Functions

func Advance

func Advance(ctx context.Context) error

Advance the simulated time, assuming that the policy mode is manual

func After

func After(ctx context.Context, deadline int64, epoch int64) (int, <-chan Completion)

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

func CancelTimer(ctx context.Context, id int) error

CancelTimer removes the designated waiting timer.

func EnsureTickInContext

func EnsureTickInContext(ctx context.Context) context.Context

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

func OutsideTime(ctx context.Context) context.Context

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

func Reset(ctx context.Context) error

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.

func Status

func Status(ctx context.Context) (*pb.StatusResponse, error)

Status retrieves the status of the Stepper service, including the current simulated time.

func Tick

func Tick(ctx context.Context) int64

Tick provides the current simulated time tick, or '-1' if the simulated time cannot be retrieved (e.g. during startup)

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

func (l *Listener) After(name string, dueTime int64, epoch int64) (int, chan Completion, error)

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.

func NewTicker

func NewTicker(ch chan *tickEvent, ep string, dialOpts ...grpc.DialOption) *Ticker

NewTicker creates a new timer collection instance. The configuration parameter provides endpoint information for the simulated time service.

func (*Ticker) Stop

func (t *Ticker) Stop()

Stop orders the ticker goroutine to stop. This is a lazy operation, where upon returning it means that the order to stop has been sent, and no further messages will be posted on the ticker event channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL