GdlrCommandMiddleware

Inherits: RefCounted < Object

Base class for command middleware.

Description

A middleware groups pipeline callbacks for one command type. Implement any of these methods. GdlrCommandPipeline.use() registers each one it finds:

class_name LogMiddleware
extends GdlrCommandMiddleware

# Runs before the handler.
func _before(envelope: CapGdlrCommandBus.CommandEnvelope, ctx: CapGdlrCommandHandlers.Context) -> void:
    print("dispatching ", envelope.command)

# Wraps the handler. Call next to continue and return its result.
func _around(next: Callable, envelope: CapGdlrCommandBus.CommandEnvelope, ctx: CapGdlrCommandHandlers.Context) -> Variant:
    return await next.call(envelope, ctx)

# Runs after the handler. Returns the result to pass on.
func _after(envelope: CapGdlrCommandBus.CommandEnvelope, ctx: CapGdlrCommandHandlers.Context, result: Variant) -> Variant:
    return result

# Optional predicates with the same arguments as the callbacks they guard.
func _should_run_before(envelope: CapGdlrCommandBus.CommandEnvelope, ctx: CapGdlrCommandHandlers.Context) -> bool:
    return true

Only _around can await. The optional predicates are _should_run_before, _should_run_around, and _should_run_after. Register the middleware with CapGdlrCommandHandlers.use().

Tutorials