H1 one consumer loop: the follower hears on the module's one consumer
In a module's own runtime the branch follower (first views) and the bundles each bound the module's durable <node>_<module>_tools with a pull loop of their own, so each event reached one of the two: the catalog revision of main.1 reached the follower and never the indexer's bundle, whose revision verb answered none-yet. The runtime now binds the consumer once, for the bundles, and hands each event to the follower after the bundles took it (runtime.WithHearer); the machine's runtime keeps the follower's own binding. Builds: design 47 H §752, H-A-113, H-A-132 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -256,6 +256,19 @@ func WithLedgerWriters(writer func(module string) (*bus.Conn, error)) Option {
|
||||
return func(c *consumers) { c.ledgers.writer = writer }
|
||||
}
|
||||
|
||||
// WithHearer hands every event of module's consumer also to hear, in process, after the module's bundles took it: the
|
||||
// consumer is bound once, for the bundles, and no second pull loop reads the same durable, so in a module's own runtime the
|
||||
// branch follower and the bundle each hear every event (design 47 H §752, H-A-113, H-A-132). An error of hear offers the
|
||||
// event again, as a bundle's does.
|
||||
func WithHearer(module string, hear func(bus.Envelope) error) Option {
|
||||
return func(c *consumers) {
|
||||
if c.hearers == nil {
|
||||
c.hearers = map[string][]func(bus.Envelope) error{}
|
||||
}
|
||||
c.hearers[module] = append(c.hearers[module], hear)
|
||||
}
|
||||
}
|
||||
|
||||
// Run launches, binds and serves, and serves each module's bundle again when it appears, changes or
|
||||
// goes, with no restart. It answers a stop function.
|
||||
func Run(conn *bus.Conn, served []Served, envs map[string]map[string]string, logf func(string, ...any), opts ...Option) (func(), error) {
|
||||
@@ -869,6 +882,8 @@ type consumers struct {
|
||||
reread func() error
|
||||
rereadMu sync.Mutex
|
||||
rereading *rereadFlight
|
||||
// hearers hear every event of a module's consumer in process, after the module's bundles took it (WithHearer).
|
||||
hearers map[string][]func(bus.Envelope) error
|
||||
// askPlain and askChunked are how a bundle's ask is sent (the bus connection's AskAs and AskAsChunked); a test gives its own.
|
||||
askPlain, askChunked func(module, key string, body any, within time.Duration) (bus.Answered, error)
|
||||
}
|
||||
@@ -1111,6 +1126,7 @@ func (c *consumers) handOut(module string, m *moduleEvents, env bus.Envelope) er
|
||||
return errModuleReloading
|
||||
}
|
||||
targets := append([]*deliverSlot(nil), m.delivers...)
|
||||
hearers := append([]func(bus.Envelope) error(nil), c.hearers[module]...)
|
||||
c.mu.Unlock()
|
||||
for _, d := range targets {
|
||||
if err := d.get()(raw); err != nil {
|
||||
@@ -1119,6 +1135,14 @@ func (c *consumers) handOut(module string, m *moduleEvents, env bus.Envelope) er
|
||||
return err
|
||||
}
|
||||
}
|
||||
// And the runtime's own hearers of the module's events, on this same consumer (WithHearer).
|
||||
for _, hear := range hearers {
|
||||
if err := hear(env); err != nil {
|
||||
c.logf("[mesh-tools] the tool runner did not take %s%s of %s's consumer: %v; offered again in %s", env.Key,
|
||||
eventRef(env), module, err, bus.NakDelay)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user