stringforwarder

package
v0.0.0-...-e653fdf Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StringForwarder

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

StringForwarder is a goroutine-safe type that pipes messages from the its Forward() method, sending them to callback. The send will not be blocked by the callback, but will instead discard messages if there is an incomplete callback in progress. The number of discarded messages is tracked and returned when the forwarder is stopped.

func New

func New(callback func(string)) *StringForwarder

New returns a new StringForwarder that sends messages to the callback, function, dropping messages if the receiver has not yet consumed the last message.

func (*StringForwarder) Forward

func (f *StringForwarder) Forward(msg string)

Forward sends the message to be processed by the callback function, discarding the message if another message is currently being processed. The number of discarded messages is recorded for reporting by the Stop method.

Forward is safe to call from multiple goroutines at once. Note that if this StringForwarder was created with a nil callback, all messages will be discarded.

func (*StringForwarder) Stop

func (f *StringForwarder) Stop() uint64

Stop cleans up the goroutine running behind StringForwarder and returns the count of discarded messages. Stop is thread-safe and may be called multiple times - after the first time, it simply returns the current discard count.

Jump to

Keyboard shortcuts

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