shelf

package
v4.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler added in v4.1.14

type Handler *func(tbk io.TimeBucketKey, data interface{}) error

Handler gets executed by a shelf on its packages.

func NewShelfHandler

func NewShelfHandler(f func(tbk io.TimeBucketKey, data interface{}) error) Handler

NewShelfHandler creates a new Handler from a supplied function.

type Package

type Package struct {
	Cancel context.CancelFunc
	Data   interface{}
	// contains filtered or unexported fields
}

Package is a data entry with a context to ensure async execution or cancellation if necessary.

func (*Package) Start

func (p *Package) Start(tbk *io.TimeBucketKey, h Handler)

Start causes the package to begin listening to it's context's done channel which is set by the deadline passed to the context. This is done in a separate goroutine.

func (*Package) Stop

func (p *Package) Stop()

Stop the package from running the handler on its data and call its context's cancel function to gracefully deallocate its resources.

type Shelf

type Shelf struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Shelf stores packages, which have shelf lives (^^) and are meant to have the shelf's handler executed after some deadline.

func NewShelf

func NewShelf(h Handler) *Shelf

NewShelf initializes a new shelf with the provided handler function.

func (*Shelf) Store

func (s *Shelf) Store(tbk *io.TimeBucketKey, data interface{}, deadline *time.Time)

Store a new package to the shelf. This operation cancels, and replaces the existing package with the same TimeBucketKey on the shelf, so make sure not to prematurely store new packages before the previous have a chance to finish naturally.

Jump to

Keyboard shortcuts

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