event

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package event provides a non-blocking event distribution and subscription system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(terminalapi.Event)

Callback is a function provided by an event subscriber. It gets called with each event that passed the subscription filter. Implementations must be thread-safe, events come from a separate goroutine. Implementation should be light-weight, otherwise a slow-processing subscriber can build a long tail of events.

type DistributionSystem

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

DistributionSystem distributes events to subscribers.

Subscribers can request filtering of events they get based on event type or subscribe to all events.

The distribution system maintains a queue towards each subscriber, making sure that a single slow subscriber only slows itself down, rather than the entire application.

This object is thread-safe.

func NewDistributionSystem

func NewDistributionSystem() *DistributionSystem

NewDistributionSystem creates a new event distribution system.

func (*DistributionSystem) Event

func (eds *DistributionSystem) Event(ev terminalapi.Event)

Event should be called with events coming from the terminal. The distribution system will distribute these to all the subscribers.

func (*DistributionSystem) Processed

func (eds *DistributionSystem) Processed() int

Processed returns the number of events that were fully processed, i.e. delivered to all the subscribers and their callbacks returned.

func (*DistributionSystem) Subscribe

func (eds *DistributionSystem) Subscribe(filter []terminalapi.Event, cb Callback, opts ...SubscribeOption) StopFunc

Subscribe subscribes to events according to the filter. An empty filter indicates that the subscriber wishes to receive events of all kinds. If the filter is non-empty, only events of the provided type will be sent to the subscriber. Returns a function that allows the subscriber to unsubscribe.

type StopFunc

type StopFunc func()

StopFunc when called unsubscribes the subscriber from all events and releases resources tied to the subscriber.

type SubscribeOption

type SubscribeOption interface {
	// contains filtered or unexported methods
}

SubscribeOption is used to provide options to Subscribe.

func MaxRepetitive

func MaxRepetitive(maxRep int) SubscribeOption

MaxRepetitive when provided, instructs the system to drop repetitive events instead of delivering them. The argument maxRep indicates the maximum number of repetitive events to enqueue towards the subscriber.

Directories

Path Synopsis
Package eventqueue provides an unboud FIFO queue of events.
Package eventqueue provides an unboud FIFO queue of events.
Package testevent provides utilities for tests that deal with concurrent events.
Package testevent provides utilities for tests that deal with concurrent events.

Jump to

Keyboard shortcuts

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