MCPcopy
hub / github.com/nats-io/nats.go / Msgs

Method Msgs

nats_iter.go:31–45  ·  view source on GitHub ↗

Msgs returns an iter.Seq2[*Msg, error] that can be used to iterate over messages. It can only be used with a subscription that has been created with SubscribeSync or QueueSubscribeSync, otherwise it will return an error on the first iteration. The iterator will block until a message is available. T

()

Source from the content-addressed store, hash-verified

29// The iterator will block until a message is available. The
30// subscription will not be closed when the iterator is done.
31func (sub *Subscription) Msgs() iter.Seq2[*Msg, error] {
32 return func(yield func(*Msg, error) bool) {
33 for {
34 msg, err := sub.nextMsgNoTimeout()
35 if err != nil {
36 yield(nil, err)
37 return
38 }
39 if !yield(msg, nil) {
40 return
41 }
42
43 }
44 }
45}
46
47// MsgsTimeout returns an iter.Seq2[*Msg, error] that can be used to iterate
48// over messages. It can only be used with a subscription that has been created

Callers 1

TestSubscribeIteratorFunction · 0.80

Calls 1

nextMsgNoTimeoutMethod · 0.95

Tested by 1

TestSubscribeIteratorFunction · 0.64