event

package
v1.4.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSubscription added in v1.1.1

func NewSubscription(handler Handler) *subscription

func NextSubscriptionID added in v1.1.1

func NextSubscriptionID() int64

Types

type DispatchService

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

func NewDispatchService

func NewDispatchService(logger ilogger.LogAdaptor) *DispatchService

NewDispatchService creates a dispatch service with the following properties. 1- It is async for the caller of Publish. Meaning Publish will not be blocked. It can be blocked because we don't have infinite channels. The queue size is 1024. 2- Events fired from the same thread for the same subscription will be handled in the same order. One will finish, then other will start. 3 - If we block an event, it will not block all events, only ones that are related to same subscription. 4 - A close after publish in the same thread waits for published item to be handled(finished) .

func (*DispatchService) Publish

func (s *DispatchService) Publish(event Event) bool

Publish an event. Events with the subscription are guaranteed to be run on the same order. If this method returns true, it is guaranteed that the dispatch service close wait for all events to be handled. Returns false if Dispatch Service is already closed.

func (*DispatchService) Stop

func (s *DispatchService) Stop(ctx context.Context) error

Stop the DispatchService and make sure that all the successful Publish events are handled before close

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) 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