Shutdown flushes pending ack sends and disconnects the Subscription.
(ctx context.Context)
| 689 | |
| 690 | // Shutdown flushes pending ack sends and disconnects the Subscription. |
| 691 | func (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" |