reactor

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCallbacksDemux added in v0.0.3

func WithCallbacksDemux[T, C any](d Demultiplexer[Event[C]]) options.Option[reactor[T, C]]

func WithCloneFn added in v0.0.3

func WithCloneFn[T any](f func(T) T) options.Option[DemuxOptions[T]]

func WithControlQueueCapcity added in v0.0.4

func WithControlQueueCapcity[T any](capacity int) options.Option[DemuxOptions[T]]

func WithEventQueue added in v0.0.2

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

func WithEventsDemux added in v0.0.3

func WithEventsDemux[T, C any](d Demultiplexer[Event[T]]) options.Option[reactor[T, C]]

func WithTimes added in v0.0.3

func WithTimes[T, C any](tick, timeout time.Duration) options.Option[reactor[T, C]]

Types

type Demultiplexer added in v0.0.3

type Demultiplexer[T any] interface {
	io.Closer
	// 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 Service[T], workers int)
	// Unregister unregisters handlers
	Unregister(id string)
}

Demultiplexer provides a thread-safe, non-blocking, asynchronous event processing. Using lock-free queues for events and control messages, and atomic pointers to manage states and workers. This component can be used instead of go channels in cases of multiple parallel readers

func NewDemux added in v0.0.3

func NewDemux[T any](opts ...options.Option[DemuxOptions[T]]) Demultiplexer[T]

type DemuxOptions added in v0.0.4

type DemuxOptions[T any] struct {
	// contains filtered or unexported fields
}

type Event added in v0.0.3

type Event[T any] struct {
	ID ID

	Data T
	Err  error
	// contains filtered or unexported fields
}

func (Event[T]) Nonce added in v0.0.3

func (e Event[T]) Nonce() int64

type EventHandler added in v0.0.3

type EventHandler[T, C any] func(T, func(C, error))

EventHandler is a function that handles events, it accepts a callback function as a second parameter. The callback function is expected to be called once the event was processed

type ID added in v0.0.3

type ID []byte

ID is the ID used for events

func IDFromString added in v0.0.3

func IDFromString(idstr string) ID

func (ID) String added in v0.0.3

func (id ID) String() string

type ReactiveService added in v0.0.3

type ReactiveService[T, C any] interface {
	Select(Event[T]) bool
	Handle(Event[T], func(C, error))
}

type Reactor

type Reactor[E, C any] interface {
	io.Closer
	Start(pctx context.Context) error

	Enqueue(events ...E)
	EnqueueWait(context.Context, E) (C, error)

	AddHandler(string, ReactiveService[E, C], int)
	RemoveHandler(string)

	AddCallback(string, Service[Event[C]], int)
	RemoveCallback(string)
}

func New

func New[T, C any](opts ...options.Option[reactor[T, C]]) Reactor[T, C]

type Service added in v0.0.3

type Service[T any] interface {
	Select(T) bool
	Handle(T)
}

Jump to

Keyboard shortcuts

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