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

Method Shutdown

pubsub/pubsub.go:281–306  ·  view source on GitHub ↗

Shutdown flushes pending message sends and disconnects the Topic. It only returns after all pending messages have been sent.

(ctx context.Context)

Source from the content-addressed store, hash-verified

279// Shutdown flushes pending message sends and disconnects the Topic.
280// It only returns after all pending messages have been sent.
281func (t *Topic) Shutdown(ctx context.Context) (err error) {
282 ctx, span := t.tracer.Start(ctx, "Topic.Shutdown")
283 defer func() { t.tracer.End(ctx, span, err) }()
284
285 t.mu.Lock()
286 if errors.Is(t.err, errTopicShutdown) {
287 defer t.mu.Unlock()
288 return t.err
289 }
290 t.err = errTopicShutdown
291 t.mu.Unlock()
292 c := make(chan struct{})
293 go func() {
294 defer close(c)
295 t.batcher.Shutdown()
296 }()
297 select {
298 case <-ctx.Done():
299 case <-c:
300 }
301 t.cancel()
302 if err := t.driver.Close(); err != nil {
303 return wrapError(t.driver, err)
304 }
305 return ctx.Err()
306}
307
308// As converts i to driver-specific types.
309// See https://gocloud.dev/concepts/as/ for background information, the "As"

Callers 15

TestSendReceiveFunction · 0.95
TestCancelSendFunction · 0.95
TestRetryTopicFunction · 0.95
TestErrorsAreWrappedFunction · 0.95
TestOpenTelemetryFunction · 0.95
TestTopicCloseIsCalledFunction · 0.95
BenchmarkNatsQueuePubSubFunction · 0.95
BenchmarkNatsPubSubFunction · 0.95
BenchmarkGcpPubSubFunction · 0.95
TestSendNoSubsFunction · 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
TestCancelSendFunction · 0.76
TestRetryTopicFunction · 0.76
TestErrorsAreWrappedFunction · 0.76
TestOpenTelemetryFunction · 0.76
TestTopicCloseIsCalledFunction · 0.76
BenchmarkNatsQueuePubSubFunction · 0.76
BenchmarkNatsPubSubFunction · 0.76
BenchmarkGcpPubSubFunction · 0.76
TestSendNoSubsFunction · 0.76