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

Method validateNextMsgState

nats.go:5490–5521  ·  view source on GitHub ↗

validateNextMsgState checks whether the subscription is in a valid state to call NextMsg and be delivered another message synchronously. This should be called while holding the lock.

(pullSubInternal bool)

Source from the content-addressed store, hash-verified

5488// state to call NextMsg and be delivered another message synchronously.
5489// This should be called while holding the lock.
5490func (s *Subscription) validateNextMsgState(pullSubInternal bool) error {
5491 if s.connClosed {
5492 return ErrConnectionClosed
5493 }
5494 if s.mch == nil {
5495 if s.max > 0 && s.delivered >= s.max {
5496 return ErrMaxMessages
5497 } else if s.closed {
5498 return ErrBadSubscription
5499 }
5500 }
5501 if s.mcb != nil {
5502 return ErrSyncSubRequired
5503 }
5504 // if this subscription previously had a permissions error
5505 // and no reconnect has been attempted, return the permissions error
5506 // since the subscription does not exist on the server
5507 if s.conn.Opts.PermissionErrOnSubscribe && s.permissionsErr != nil {
5508 return s.permissionsErr
5509 }
5510 if s.sc {
5511 s.changeSubStatus(SubscriptionActive)
5512 s.sc = false
5513 return ErrSlowConsumer
5514 }
5515 // Unless this is from an internal call, reject use of this API.
5516 // Users should use Fetch() instead.
5517 if !pullSubInternal && s.jsi != nil && s.jsi.pull {
5518 return ErrTypeSubscription
5519 }
5520 return nil
5521}
5522
5523// This is called when the sync channel has been closed.
5524// The error returned will be either connection or subscription

Callers 3

NextMsgMethod · 0.95
nextMsgNoTimeoutMethod · 0.95
nextMsgWithContextMethod · 0.95

Calls 1

changeSubStatusMethod · 0.95

Tested by

no test coverage detected