uevent

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastWatcher

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

BroadcastWatcher is an implementation of the Watcher interface that allows multiple parallel listeners to receive the same messages from a single channel. It's pretty similar to ParallelWatcher, but allows multiple parallel listeners to receive the same messages.

Fields: - input: The input channel to be watched for incoming messages. - listeners: A slice of listeners channels for registered listeners. - m: A mutex to ensure that Register and other operations are thread-safe. - started: An atomic boolean to ensure the Start method is only called once.

func NewBroadcastWatcher

func NewBroadcastWatcher[T any](input <-chan T) *BroadcastWatcher[T]

NewBroadcastWatcher creates a new instance of BroadcastWatcher. Parameters: - input: The input channel to be watched for incoming messages. Returns: - A pointer to a newly created BroadcastWatcher instance.

func (*BroadcastWatcher[T]) Register

func (w *BroadcastWatcher[T]) Register(f watchFunc[T])

Register registers a new listener and returns a read-only channel for the listener to receive messages. This method is thread-safe and can be called concurrently by multiple goroutines. Note that using locks can introduce contention and affect performance in highly concurrent environments.

func (*BroadcastWatcher[T]) Watch

func (w *BroadcastWatcher[T]) Watch(ctx context.Context) bool

Watch starts the broadcasting process, sending each message from the input channel to all registered listeners. This method is thread-safe and ensures that the broadcasting process can only be started once. Multiple calls to this method will have no effect after the first call. Note that using locks can introduce contention and affect performance in highly concurrent environments. Parameters: - ctx: The context to control cancellation of the watching operation. Returns: - A boolean indicating whether the broadcasting process was successfully started.

type ParallelWatcher

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

ParallelWatcher is a generic implementation of the Watcher interface. It ensures that only a single goroutine receives specific message from the provided channel. In case you need to listen to each messages in every listener, consider using BroadcastWatcher.

The ParallelWatcher struct is parameterized with two types: - T: The type of the messages in the channel. - C: The type of the channel itself, which should be a channel of T.

Fields: - ch: The channel to be watched for incoming messages. - f: The function to be called with each message read from the channel. - m: A mutex to ensure that Watch is thread-safe. - watching: An atomic boolean to track whether a watcher is currently active.

func NewParallelWatcher added in v1.17.8

func NewParallelWatcher[T any](ch <-chan T, f watchFunc[T]) *ParallelWatcher[T]

func (*ParallelWatcher[T]) Register

func (w *ParallelWatcher[T]) Register(f watchFunc[T])

Register replaces the watching function in case it's required.

func (*ParallelWatcher[T]) Watch

func (w *ParallelWatcher[T]) Watch(ctx context.Context) bool

Watch starts a goroutine to watch the channel for incoming messages and call the provided function with each message. If the channel is nil, the function is nil, or a watcher is already active, it returns false. The context.Context parameter allows for cancelling the watching operation. Parameters: - ctx: The context to control cancellation of the watching operation. Returns: - A boolean indicating whether the watcher was successfully started.

type Watcher

type Watcher[T any] interface {
	Register(f watchFunc[T])        // Registers watching function depending on watcher implementation
	Watch(ctx context.Context) bool // Starts watching
}

Watcher is an interface that defines a method to start watching a channel for incoming messages. The Watch method takes a context.Context to allow for cancellation and returns a boolean indicating whether the watcher was successfully started.

Jump to

Keyboard shortcuts

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