cursor

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cursor implements time-ordered item cursors for an event log.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

A Cursor is a unique identifier for an item in a time-ordered event log. It is safe to copy and compare cursors by value.

func (Cursor) Before

func (c Cursor) Before(o Cursor) bool

Before reports whether c is prior to o in time ordering. This comparison ignores sequence numbers.

func (Cursor) Diff

func (c Cursor) Diff(o Cursor) time.Duration

Diff returns the time duration between c and o. The duration is negative if c is before o in time order.

func (Cursor) IsZero

func (c Cursor) IsZero() bool

IsZero reports whether c is the zero cursor.

func (Cursor) MarshalText

func (c Cursor) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. A zero cursor marshals as "", otherwise the format used by the String method.

func (Cursor) String

func (c Cursor) String() string

String returns a printable text representation of a cursor.

func (*Cursor) UnmarshalText

func (c *Cursor) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. An empty text unmarshals without error to a zero cursor.

type Source

type Source struct {
	// This function is called to produce the current time index.
	// If nil, it defaults to time.Now().UnixNano().
	TimeIndex func() int64

	// The current counter value used for sequence number generation.  It is
	// incremented in-place each time a cursor is generated.
	Counter int64
}

A Source produces cursors based on a time index generator and a sequence counter. A zero-valued Source is ready for use with defaults as described.

func (*Source) Cursor

func (s *Source) Cursor() Cursor

Cursor produces a fresh cursor from s at the current time index and counter.

Jump to

Keyboard shortcuts

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