event

package
v1.0.0-preview.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSubscriptionID = -1

Variables

View Source
var ErrDispatchServiceNotRunning = errors.New("dispatch service not running")

Functions

func FormatSubscriptionID

func FormatSubscriptionID(id int64) string

func MakeSubscriptionID

func MakeSubscriptionID(fun interface{}) int64

MakeSubscriptionID creates subscription ID from a function

func ParseSubscriptionID

func ParseSubscriptionID(id string) (int64, error)

Types

type DispatchService

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

func NewDispatchService

func NewDispatchService() *DispatchService

func (*DispatchService) Publish

func (s *DispatchService) Publish(event Event)

func (*DispatchService) Stop

func (s *DispatchService) Stop()

func (*DispatchService) Subscribe

func (s *DispatchService) Subscribe(eventName string, subscriptionID int64, handler Handler)

Subscribe attaches handler to listen for events with eventName. Do not rely on the order of handlers, they may be shuffled.

func (*DispatchService) SubscribeSync

func (s *DispatchService) SubscribeSync(eventName string, subscriptionID int64, handler Handler)

SubscribeSync attaches handler to listen for events with eventName. Sync handlers are dispatched first, the events are ordered. Do not rely on the order of handlers, they may be shuffled.

func (*DispatchService) Unsubscribe

func (s *DispatchService) Unsubscribe(eventName string, subscriptionID int64)

type Event

type Event interface {
	EventName() string
}

type Handler

type Handler func(event Event)

Jump to

Keyboard shortcuts

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