requestbuffer

package
v0.0.0-...-2a45ea8 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package requestbuffer provides a storage for a consistent set of Request and corresponding Reply messages. It allows to asynchronously add and remove messages, as well as to subscribe for new messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

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

T implements the storage to keep and coordinate flow and processing of Request and Reply messages. All methods are safe to invoke concurrently. Current implementation has capacity for a single request only.

func New

func New() *T

New creates a new instance of the request buffer

func (*T) AddReply

func (rb *T) AddReply(msg messages.Reply) bool

AddReply adds a new Reply message to the buffer. Messages with no corresponding Request message in the buffer will be dropped. Any subsequent Reply message with the same replica ID corresponding to the same Request will be dropped. The return value indicates if the message was accepted.

func (*T) AddRequest

func (rb *T) AddRequest(msg messages.Request, cancel <-chan struct{}) (<-chan messages.Reply, bool)

AddRequest adds a new Request message to the buffer. Each subsequent invocation should supply a message with increasing non-zero sequence ID. It will block if there's no capacity available for the new message. The corresponding Reply messages are to be received from the returned channel as they are added with AddReply. The returned channel is closed when RemoveRequest is invoked for the Request message. The returned boolean value indicates if the message was accepted.

func (*T) RemoveRequest

func (rb *T) RemoveRequest(seq uint64)

RemoveRequest removes a Request message and all corresponding Reply messages given a sequence ID of the Request message.

func (*T) RequestStream

func (rb *T) RequestStream(cancel <-chan struct{}) <-chan messages.Request

RequestStream returns a channel to receive all Request messages as they are added with AddRequest. Closing the channel passed to this function indicates the returned channel should be closed. Nil channel may be passed if there's no need to close the returned channel.

Jump to

Keyboard shortcuts

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