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 ¶
- type Carrier
- func (c *Carrier) Carry(queues ...CommandQueue) error
- func (c *Carrier) Empty() bool
- func (c *Carrier) Put(issuer Issuer, cmd Command) bool
- func (c *Carrier) PutFrom(entity uid.UID64, cmd Command) bool
- func (c *Carrier) PutFromOf[C Command](entity uid.UID64, cmd C) bool
- func (c *Carrier) Takes(t reflect.Type) bool
- type Command
- type CommandQueue
- type Issued
- type Issuer
- type Queue
- func (q *Queue[C]) Accepts() reflect.Type
- func (q *Queue[C]) Add(issuer Issuer, cmd C)
- func (q *Queue[C]) AddFrom(entity uid.UID64, cmd C)
- func (q *Queue[C]) Drain(fn func(i Issued[C]))
- func (q *Queue[C]) Empty() bool
- func (q *Queue[C]) Put(issuer Issuer, cmd Command)
- func (q *Queue[C]) PutFrom(entity uid.UID64, cmd Command)
- type Routed
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) Put ¶
Put takes cmd, given by issuer, to the queue of its type; false when none takes it.
func (*Carrier) PutFrom ¶
PutFrom takes cmd, given by entity for itself, to the queue of its type; false when none takes it.
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{}.
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 ¶
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.