future

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout is returned when the operation timeout is exceeded.
	ErrTimeout = errors.New("timeout")
	// ErrChannelClosed is returned when the input channel is closed.
	ErrChannelClosed = errors.New("channel closed")
)

Functions

This section is empty.

Types

type CancelCallback

type CancelCallback func(Future)

CancelCallback is a callback function executed when cancelling Future.

type Future

type Future interface {

	// ID returns packet sequence number.
	ID() types.RequestID

	// Receiver returns the initiator of the packet.
	Receiver() *legacyhost.Host

	// Request returns origin request.
	Request() network.Packet

	// Response is a channel to listen for future response.
	Response() <-chan network.ReceivedPacket

	// SetResponse makes packet to appear in response channel.
	SetResponse(network.ReceivedPacket)

	// WaitResponse gets the future response from Response() channel with a timeout set to `duration`.
	WaitResponse(duration time.Duration) (network.ReceivedPacket, error)

	// Cancel closes all channels and cleans up underlying structures.
	Cancel()
}

Future is network response future.

func NewFuture

func NewFuture(requestID types.RequestID, receiver *legacyhost.Host, packet *rms.Packet, cancelCallback CancelCallback) Future

NewFuture creates a new Future.

type Manager

type Manager interface {
	Get(packet *rms.Packet) Future
	Create(packet *rms.Packet) Future
}

func NewManager

func NewManager() Manager

type PacketHandler

type PacketHandler interface {
	Handle(ctx context.Context, msg *packet.ReceivedPacket)
}

func NewPacketHandler

func NewPacketHandler(futureManager Manager) PacketHandler

Jump to

Keyboard shortcuts

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