bus

package
v0.0.0-...-1e82369 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublishNSUpdate

func PublishNSUpdate(update *dto.NSUpdate)

func SubscribeNSUpdate

func SubscribeNSUpdate(callback func(update *dto.NSUpdate)) error

Types

type Bus

type Bus interface {
	Subscriber
	Publisher
}

func New

func New() Bus

type EventBus

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

func (*EventBus) Publish

func (bus *EventBus) Publish(topic string, args ...interface{})
Example
calculator1 := func(a int, b int) {
	fmt.Println(a + b)
}

bus := New()
if err := bus.Subscribe("main:calculator", calculator1); err != nil {
	panic(err)
}

bus.Publish("main:calculator", 20, 40)
bus.Publish("main:calculator", 1, 1)
bus.Publish("main:calculator", 1, 2)

if err := bus.Subscribe("main:calculator", calculator1); err != nil {
	panic(err)
}

bus.Publish("main:calculator", 20, 40)
bus.Publish("main:calculator", 1, 1)
bus.Publish("main:calculator", 1, 2)
Output:

60
2
3
60
60
2
2
3
3

func (*EventBus) Subscribe

func (bus *EventBus) Subscribe(topic string, fn interface{}) error

type Publisher

type Publisher interface {
	Publish(topic string, args ...interface{})
}

type Subscriber

type Subscriber interface {
	Subscribe(topic string, fn interface{}) error
}

Jump to

Keyboard shortcuts

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