event

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: AGPL-3.0 Imports: 6 Imported by: 37

Documentation

Overview

Package event deals with subscriptions to real-time events.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMuxClosed is returned when Posting on a closed TypeMux.
	ErrMuxClosed = errors.New("event: mux closed")
	//ErrDuplicateSubscribe is returned when subscribe duplicate type
	ErrDuplicateSubscribe = errors.New("event: subscribe duplicate type")
)

Functions

This section is empty.

Types

type Dispatcher

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

A Dispatcher dispatches events to registered receivers. Receivers can be registered to handle events of certain type. Any operation called after mux is stopped will return ErrMuxClosed.

The zero value is ready to use.

func NewDispatcher

func NewDispatcher() *Dispatcher

func (*Dispatcher) Post

func (d *Dispatcher) Post(ev interface{}) error

Post sends an event to all receivers registered for the given type. It returns ErrMuxClosed if the mux has been stopped.

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop closes a mux. The mux can no longer be used. Future Post calls will fail with ErrMuxClosed. Stop blocks until all current deliveries have finished.

func (*Dispatcher) Subscribe

func (d *Dispatcher) Subscribe(types ...interface{}) (*Subscription, error)

Subscribe creates a subscription for events of the given types. The subscription's channel is closed when it is unsubscribed or the mux is closed.

type NewMinedBlockEvent

type NewMinedBlockEvent struct{ Block types.Block }

type Subscription

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

Subscription is a subscription established through TypeMux.

func (*Subscription) Chan

func (s *Subscription) Chan() <-chan *TypeMuxEvent

func (*Subscription) Closed

func (s *Subscription) Closed() bool

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

type TypeMuxEvent

type TypeMuxEvent struct {
	Time time.Time
	Data interface{}
}

TypeMuxEvent is a time-tagged notification pushed to subscribers.

Jump to

Keyboard shortcuts

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