mailbox

package
v0.0.0-...-78a8314 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Overview

Every Mailbox is safe for multiple concurrent writers, and one reader. It is unbounded in length.

Index

Constants

View Source
const InitialMsgChanLen = 16

Variables

This section is empty.

Functions

func NewMailbox

func NewMailbox[T any]() (writer *MailboxWriter[T], reader *MailboxReader[T])

Types

type MailboxReader

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

do not attempt to access the same reader from >1 go-routine

func (*MailboxReader[T]) IsEmpty

func (self *MailboxReader[T]) IsEmpty() (empty bool)

For use by the reader go-routine only. Returns true iff the mailbox is currently empty.

func (*MailboxReader[T]) Length

func (self *MailboxReader[T]) Length() (length int)

For use by the reader go-routine only

func (*MailboxReader[T]) Receive

func (self *MailboxReader[T]) Receive() T

For use by the reader go-routine only.

func (*MailboxReader[T]) Terminate

func (self *MailboxReader[T]) Terminate()

Used by the reader to indicate the reader has exited. It is idempotent.

type MailboxWriter

type MailboxWriter[T any] struct {
	TerminatedChan <-chan struct{}
	// contains filtered or unexported fields
}

a writer can be safely used across multiple go routines

func (*MailboxWriter[T]) Send

func (self *MailboxWriter[T]) Send(msg T) (success bool)

returns false if the channel has been terminated. true indicates the msg has been sent, not that it's going to be received or processed.

func (*MailboxWriter[T]) WaitForTermination

func (self *MailboxWriter[T]) WaitForTermination()

type MsgChanCell

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

We form a linked-list of MsgChanCells.

Jump to

Keyboard shortcuts

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