eventbus

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0, MIT Imports: 6 Imported by: 35

README

go-eventbus

GoDoc Coverage Status Build Status Discourse posts

Simple and fast eventbus for type-based local event delivery.

Install

go get github.com/libp2p/go-eventbus

Usage

Check out the GoDocs.

License

Dual-licensed under MIT and ASLv2, by way of the Permissive License Stack.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForceSubType

func ForceSubType(evtType interface{}) event.SubscriptionOpt

ForceSubType is a Subscribe option which overrides the type to which the subscription will be done. Note that the evtType must be assignable to channel type.

This also allows for subscribing to multiple eventbus channels with one Go channel to get better ordering guarantees.

Example: type Event struct{}

func (Event) String() string {
   return "event"
}

eventCh := make(chan fmt.Stringer) // interface { String() string } cancel, err := eventbus.Subscribe(eventCh, event.ForceSubType(new(Event))) [...]

func NewBus

func NewBus() event.Bus

func Stateful

func Stateful(s interface{}) error

Stateful is an Emitter option which makes makes the eventbus channel 'remember' last event sent, and when a new subscriber joins the bus, the remembered event is immediately sent to the subscription channel.

This allows to provide state tracking for dynamic systems, and/or allows new subscribers to verify that there are Emitters on the channel

Types

type Emitter

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

func (*Emitter) Close

func (e *Emitter) Close() error

func (*Emitter) Emit

func (e *Emitter) Emit(evt interface{})

Jump to

Keyboard shortcuts

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