reactor

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](opts ...options.Option[reactor[T]]) *reactor[T]

func WithControlQueue added in v0.0.2

func WithControlQueue[T any](q core.Queue[controlEvent[T]]) options.Option[reactor[T]]

func WithEventQueue added in v0.0.2

func WithEventQueue[T any](q core.Queue[T]) options.Option[reactor[T]]

Types

type Handler

type Handler[T any] func(T)

Handler is a function that handles events

type Reactor

type Reactor[T any] interface {
	// Start starts the event loop
	Start(context.Context) error
	// Enqueue adds a new event to the event queue
	Enqueue(T)
	// Register registers handlers. It accepts the event selector, amount of goroutine workers
	// that will be used to process events, and the handlers that will be called.
	Register(id string, s Selector[T], workers int, handlers ...Handler[T])
	// Unregister unregisters handlers
	Unregister(id string)
}

Reactor provides a thread-safe, non-blocking, asynchronous event processing. It uses lock-free queues for events and control messages.

type Selector

type Selector[T any] func(T) bool

Selector is a predicate that selects events for a given set of handlers

Jump to

Keyboard shortcuts

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