H-A-196: one SDK function claims, pulls and wraps a durable's loop
The tool runner would otherwise copy the claim's wrapper (review round 1, P7): ConsumeOnce claims the durable, pulls it and answers the loop, and HearEvents uses it; Conn.Consume claims through the same guard. A drain keeps its claim until the loop ended, and the loop's Closed is closed only once the claim is released, so a bind during a drain is refused and one after it is never. Builds: design 47 H H-A-196, H-A-197
This commit is contained in:
+2
-11
@@ -105,18 +105,9 @@ func (a Account) namedEventConsumerName(suffix string) string {
|
||||
|
||||
// HearEvents pulls from cons, handing each message to handle, and says every error the bus reports while
|
||||
// hearing through logf ("hearing the bus: ..."). The caller stops the returned context. A durable this process pulls
|
||||
// already is refused (PullOnce, design 47 H, H-A-196).
|
||||
// already is refused (ConsumeOnce, design 47 H, H-A-196).
|
||||
func HearEvents(cons jetstream.Consumer, handle func(jetstream.Msg), logf func(string, ...any)) (jetstream.ConsumeContext, error) {
|
||||
release, err := PullOnce(cons, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cc, err := cons.Consume(handle, jetstream.ConsumeErrHandler(func(_ jetstream.ConsumeContext, err error) {
|
||||
return ConsumeOnce(cons, callerOutside(), handle, jetstream.ConsumeErrHandler(func(_ jetstream.ConsumeContext, err error) {
|
||||
logf("hearing the bus: %v", err)
|
||||
}))
|
||||
if err != nil {
|
||||
release()
|
||||
return nil, err
|
||||
}
|
||||
return claimed(cc, release), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user