command

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 3 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 command is how anything is asked for: a command is a value carried by its type to the one handler whose queue takes it, from a user and from an entity alike, and waits there for the handler's pass. Nothing is dropped and nothing is called back.

Command and Queue

A type is a Command by its method Command, a mark confirmed where it is defined. A Queue holds the commands of one type as Issued — by an Issuer outside the entities, or by an entity for itself — until its handler drains them. CommandQueue is a Queue with its type erased.

Carrier

A Carrier takes each command to the queue of its type, one carrier for every queue in use; a Routed command is written one way and carried as another, and Unwrap is what the handler takes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Carrier

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

Carrier takes each command to the queue of its type. Nothing is dropped: a command waits in its queue for its handler's pass.

func (*Carrier) Carry

func (c *Carrier) Carry(queues ...CommandQueue) error

Carry adds queues to those c takes commands to; a type another queue takes already is an error.

func (*Carrier) Empty

func (c *Carrier) Empty() bool

Empty reports whether every command given has been drained.

func (*Carrier) Put

func (c *Carrier) Put(issuer Issuer, cmd Command) bool

Put takes cmd, given by issuer, to the queue of its type; false when none takes it.

func (*Carrier) PutFrom

func (c *Carrier) PutFrom(entity uid.UID64, cmd Command) bool

PutFrom takes cmd, given by entity for itself, to the queue of its type; false when none takes it.

func (*Carrier) Takes

func (c *Carrier) Takes(t reflect.Type) bool

Takes reports whether a queue takes commands of type t.

type Command

type Command interface{ Command() }

Command is what somebody asks for: carried by its type to the one handler whose queue takes it. A type is a command by its method Command, a mark never called, confirmed where it is defined: var _ command.Command = MoveTo{}.

func Unwrap

func Unwrap(cmd Command) Command

Unwrap is cmd as its handler takes it: itself, or what a Routed command says.

type CommandQueue

type CommandQueue interface {
	Accepts() reflect.Type
	Put(issuer Issuer, cmd Command)
	PutFrom(entity uid.UID64, cmd Command)
	Empty() bool
}

CommandQueue is a Queue with its command type erased, as a carrier sorts commands into them.

type Issued

type Issued[C Command] struct {
	Issuer   Issuer
	Entity   uid.UID64
	ByEntity bool
	Command  C
}

Issued is one command as its handler reads it: who gave it — an Issuer, or with ByEntity an entity for itself — and what it says.

type Issuer

type Issuer uint8

Issuer numbers whoever outside the entities gives commands: a user, a client, a script; Nobody is a command nobody in particular gave.

const Nobody Issuer = 0

Nobody is the Issuer of a command with nobody behind it.

type Queue

type Queue[C Command] struct {
	// contains filtered or unexported fields
}

Queue holds the commands of one type until the plugin that owns it drains them in its own pass.

func (*Queue[C]) Accepts

func (q *Queue[C]) Accepts() reflect.Type

func (*Queue[C]) Add

func (q *Queue[C]) Add(issuer Issuer, cmd C)

Add puts cmd in as given by issuer.

func (*Queue[C]) AddFrom

func (q *Queue[C]) AddFrom(entity uid.UID64, cmd C)

AddFrom puts cmd in as given by entity for itself.

func (*Queue[C]) Drain

func (q *Queue[C]) Drain(fn func(i Issued[C]))

Drain hands every command to fn in the order given and empties the queue.

func (*Queue[C]) Empty

func (q *Queue[C]) Empty() bool

Empty reports whether nothing is waiting.

func (*Queue[C]) Put

func (q *Queue[C]) Put(issuer Issuer, cmd Command)

func (*Queue[C]) PutFrom

func (q *Queue[C]) PutFrom(entity uid.UID64, cmd Command)

type Routed

type Routed interface{ Routed() Command }

Routed is a command written one way and carried as another: Routed is the command its handler takes.

Jump to

Keyboard shortcuts

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