mailbox

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mailbox is the coalesced-wake queue every loop messenger shares: items appended from any goroutine, drained in order on the loop by one closure the first append schedules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Box

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

Box queues items for one drain closure. The zero value is ready.

func (*Box[T]) Pending

func (b *Box[T]) Pending() int

Pending counts the queued items.

func (*Box[T]) Put

func (b *Box[T]) Put(item T) bool

Put appends item and reports whether the caller must schedule the drain: true only for the first append since the last Take. A stopped box drops the item and reports false.

func (*Box[T]) Release added in v0.2.5

func (b *Box[T]) Release(batch []T)

Release takes back a batch Take returned, dropping what it references. A storm's oversized batch goes to the collector instead.

func (*Box[T]) Stop

func (b *Box[T]) Stop()

Stop drops the queued items and makes every later Put a no-op.

func (*Box[T]) Stopped

func (b *Box[T]) Stopped() bool

Stopped reports whether Stop ran.

func (*Box[T]) Take

func (b *Box[T]) Take() []T

Take returns the queued items in order and disarms the box, so the next Put schedules a fresh drain. Handing the batch to Release when it is done with spares the next batch an allocation.

Jump to

Keyboard shortcuts

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