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

Method Close

runtimevar/runtimevar.go:293–320  ·  view source on GitHub ↗

Close closes the Variable. The Variable is unusable after Close returns.

()

Source from the content-addressed store, hash-verified

291
292// Close closes the Variable. The Variable is unusable after Close returns.
293func (c *Variable) Close() error {
294 // Record that we're closing. Subsequent calls to Watch/Latest will return ErrClosed.
295 c.mu.Lock()
296 if errors.Is(c.lastErr, ErrClosed) {
297 c.mu.Unlock()
298 return ErrClosed
299 }
300 c.last = Snapshot{}
301 c.lastErr = ErrClosed
302
303 // Close any remaining channels to wake up any callers that are waiting on them.
304 close(c.changed)
305 // If it's the first good value, close haveGoodCh so that Latest doesn't block.
306 select {
307 case <-c.haveGoodCh:
308 default:
309 close(c.haveGoodCh)
310 }
311 c.mu.Unlock()
312
313 // Shut down the background goroutine.
314 c.backgroundCancel()
315 <-c.backgroundDone
316
317 // Close the driver.
318 err := c.dw.Close()
319 return wrapError(c.dw, err)
320}
321
322func wrapError(w driver.Watcher, err error) error {
323 if err == nil {

Callers 1

openVariableFunction · 0.95

Calls 3

IsMethod · 0.80
wrapErrorFunction · 0.70
CloseMethod · 0.65

Tested by 1

openVariableFunction · 0.76