mailbox

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 4 Imported by: ? 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 decides which connected copy of an agent gets the next task.

Each agent address can have several tunnel sessions (copies of the agent on a laptop, a server, a GPU box), and each session says how many tasks it runs at once. Together they form a worker pool. Acquire hands out a slot on the least busy session and blocks while every session is full or none is connected, which is how a task waits for an offline agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mailbox

type Mailbox struct {

	// OnChange, if set, is called (without the lock held) after an address's stats change.
	OnChange func(handle string, stats Stats)
	// contains filtered or unexported fields
}

Mailbox tracks the sessions of every address.

func New

func New() *Mailbox

New returns an empty mailbox.

func (*Mailbox) Acquire

func (m *Mailbox) Acquire(ctx context.Context, handle string, onWait func()) (s Session, release func(), err error)

Acquire waits for a free slot on one of handle's sessions. onWait, if not nil, is called once when Acquire has to wait. release must be called when the task is done with the session.

func (*Mailbox) Add

func (m *Mailbox) Add(handle string, s Session)

Add registers a session for handle until the session is done.

func (*Mailbox) All

func (m *Mailbox) All() map[string]Stats

All returns the stats of every address that has or had sessions.

func (*Mailbox) Any

func (m *Mailbox) Any(handle string) Session

Any returns some live session of handle without taking a slot, for short calls such as fetching the card or cancelling a task.

func (*Mailbox) Stats

func (m *Mailbox) Stats(handle string) Stats

Stats returns handle's current stats.

type Session

type Session interface {
	// ID identifies the session.
	ID() string
	// Capacity is how many tasks the session runs at once.
	Capacity() int
	// Transport sends HTTP requests to the agent through the session.
	Transport() http.RoundTripper
	// Done is closed when the session ends.
	Done() <-chan struct{}
}

Session is one connected copy of an agent.

type Stats

type Stats struct {
	Sessions int `json:"sessions"`
	Capacity int `json:"capacity"`
	InFlight int `json:"inFlight"`
	Waiting  int `json:"waiting"`
}

Stats describes an address's mailbox.

Jump to

Keyboard shortcuts

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