CapGdlrCommandBus¶
Inherits: GdlrCapability < RefCounted < Object
Capability that dispatches commands.
Description¶
A command is a serializable request. The bus wraps it in a CapGdlrCommandBus.CommandEnvelope, runs the envelope through the bus middleware, and then executes it according to CapGdlrCommandBus.CommandRoute.exec_kind: local handlers from CapGdlrCommandHandlers, a remote CapGdlrCommandTransport, or both.
Godular ships a service for this capability at res://addons/godular/built_ins/services/command_bus.svc.gd. It needs a CapGdlrCommandHandlers and a CapGdlrCommandTransport:
const SvcCommandBus = preload("res://addons/godular/built_ins/services/command_bus.svc.gd")
const SvcCommandHandlers = preload("res://addons/godular/built_ins/services/command_handlers.svc.gd")
static var PROVIDERS = {
CapGdlrCommandHandlers: {"use": SvcCommandHandlers},
CapGdlrCommandTransport: {"use": MyTransport},
CapGdlrCommandBus: {
"use": SvcCommandBus,
"inject": [CapGdlrCommandHandlers, CapGdlrCommandTransport],
},
}
Tutorials¶
Methods¶
void |
|
void |
clear_middleware() abstract |
dispatch(command_or_envelope: Variant, meta_params: Dictionary = {}) abstract |
Enumerations¶
enum CommandStatus: 🔗
CommandStatus NACK = 0
The command was not accepted. CapGdlrCommandBus.CommandResult.reason explains why.
CommandStatus ACK = 1
The command was accepted.
CommandStatus TIMEOUT = 2
The command timed out.
enum ExecKind: 🔗
ExecKind NONE = -1
No route. The bus rejects the command.
ExecKind LOCAL = 0
Local handlers only.
ExecKind REMOTE = 1
The remote transport only.
ExecKind DUAL_LOCAL_FIRST = 2
Local handlers first, then the remote transport. The remote result is returned.
ExecKind DUAL_REMOTE_FIRST = 3
The remote transport first, then local handlers. The remote result is returned.
Method Descriptions¶
void use(middleware: Callable) abstract 🔗
Adds bus middleware. middleware receives the next step of the chain and returns a callable that takes an envelope and returns a CapGdlrCommandBus.CommandResult:
bus.use(func(next: Callable) -> Callable:
return func(envelope: CapGdlrCommandBus.CommandEnvelope):
print("dispatching ", envelope.command)
return await next.call(envelope)
)
The first middleware added is the outer layer.
void clear_middleware() abstract 🔗
Removes every bus middleware.
CapGdlrCommandBus.CommandResult dispatch(command_or_envelope: Variant, meta_params: Dictionary = {}) abstract 🔗
Dispatches a command and returns its result. command_or_envelope is a CapGdlrCommandBus.Command or a CapGdlrCommandBus.CommandEnvelope. For a command, the bus creates a CapGdlrCommandBus.CommandMeta and sets each key of meta_params on it. The envelope must have a CapGdlrCommandBus.CommandMeta.route.