MCPcopy Create free account
hub / github.com/google/go-cloud / Shutdown

Method Shutdown

pubsub/pubsub.go:691–725  ·  view source on GitHub ↗

Shutdown flushes pending ack sends and disconnects the Subscription.

(ctx context.Context)

Source from the content-addressed store, hash-verified

689
690// Shutdown flushes pending ack sends and disconnects the Subscription.
691func (s *Subscription) Shutdown(ctx context.Context) (err error) {
692 ctx, span := s.tracer.Start(ctx, "Subscription.Shutdown")
693 defer func() { s.tracer.End(ctx, span, err) }()
694
695 s.mu.Lock()
696 if errors.Is(s.err, errSubscriptionShutdown) {
697 // Already Shutdown.
698 defer s.mu.Unlock()
699 return s.err
700 }
701 s.err = errSubscriptionShutdown
702 s.mu.Unlock()
703 c := make(chan struct{})
704 go func() {
705 defer close(c)
706 if s.ackBatcher != nil {
707 s.ackBatcher.Shutdown()
708 }
709 }()
710 select {
711 case <-ctx.Done():
712 case <-c:
713 }
714 s.cancel()
715 if err := s.driver.Close(); err != nil {
716 return wrapError(s.driver, err)
717 }
718 s.mu.Lock()
719 defer s.mu.Unlock()
720 if err := s.unreportedAckErr; err != nil {
721 s.unreportedAckErr = nil
722 return err
723 }
724 return ctx.Err()
725}
726
727// As converts i to driver-specific types.
728// See https://gocloud.dev/concepts/as/ for background information, the "As"

Callers 15

TestSendReceiveFunction · 0.95
TestCancelReceiveFunction · 0.95
TestCancelTwoReceivesFunction · 0.95
TestRetryReceiveFunction · 0.95
TestBatchSizeDecaysFunction · 0.95
TestErrorsAreWrappedFunction · 0.95
TestOpenTelemetryFunction · 0.95

Calls 8

StartMethod · 0.80
EndMethod · 0.80
IsMethod · 0.80
DoneMethod · 0.80
ErrMethod · 0.80
wrapErrorFunction · 0.70
ShutdownMethod · 0.65
CloseMethod · 0.65

Tested by 15

TestSendReceiveFunction · 0.76
TestCancelReceiveFunction · 0.76
TestCancelTwoReceivesFunction · 0.76
TestRetryReceiveFunction · 0.76
TestBatchSizeDecaysFunction · 0.76
TestErrorsAreWrappedFunction · 0.76
TestOpenTelemetryFunction · 0.76