messagewindow

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosedMessageWindow = errors.New("Message window have been closed")

ErrClosedMessageWindow is an error that senders oberve if window have been closed.

Functions

This section is empty.

Types

type MessageWindow

type MessageWindow[S constraints.Integer, T any] interface {
	// Send message into this window.
	// This method won't block and concurrency safe.
	//
	// Sequence number must start with 0.
	//
	// If this window have been closed by the consumer, returns ErrClosedMessageWindow
	Send(sequence S, msg T) error

	// Consume message from this window.
	//
	// Because the aim of this window is to provide sequential message stream, only one goroutine should consume messages.
	// If multiple goroutines consume, the result is not guaranteed.
	//
	// If this window have been closed (= end of sequence), this method returns io.EOF.
	// Also, this method block until next message, context cancelation, or close.
	Consume(ctx context.Context) (S, T, error)

	// Close means the end of message sequence (if sender call) or means receiver's will to not receive message anymore.
	// At least one of sender or receiver must call Close to avoid resource leakage.
	// Concurrent / duplicated call of Close() is fine.
	Close()
}

MessageWindow is an object that bridge incoming messages to a consumer, with following guarantees: - Message sender won't be blocked always - Consumer will observe sorted message sequence

func NewMessageWindow

func NewMessageWindow[S constraints.Integer, T any]() MessageWindow[S, T]

Jump to

Keyboard shortcuts

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