The Observer
Subscribing to hermetic build events.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Awareness
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// STARLARK PATTERN //
def create_event_bus():
state = {"subscribers": []}
def _subscribe(subscriber_func):
state["subscribers"].append(subscriber_func)
def _publish(event_name, data):
results = []
for sub in state["subscribers"]:
results.append(sub(event_name, data))
return results
return struct(
subscribe = _subscribe,
publish = _publish
)
def logger_subscriber(event, data):
return "Log: Event %s occurred with %s" % (event, data)
# Usage
bus = create_event_bus()
bus.subscribe(logger_subscriber)
bus.publish("TARGET_BUILT", "main.o")
The Observer pattern enables a publish-subscribe mechanism within Starlark configuration phases. Since macros often generate auxiliary files (like test runners or coverage reports), an event bus struct can allow loosely coupled modules to listen for “TARGET_GENERATED” events and automatically inject their own supplemental build instructions into the graph.
Runic Tags:
#behavioral
#starlark
#hermetic