| 1 | package plugin |
| 2 | |
| 3 | func (c *Client) close() { |
| 4 | if c == nil { |
| 5 | return |
| 6 | } |
| 7 | c.closeOnce.Do(func() { |
| 8 | c.closed.Store(true) |
| 9 | c.refresh.mu.Lock() |
| 10 | c.refresh.closed = true |
| 11 | c.refresh.onChanged = nil |
| 12 | stopNotifications := c.refresh.stopNotifications |
| 13 | c.refresh.stopNotifications = nil |
| 14 | cancelRefresh := c.refresh.cancel |
| 15 | c.refresh.mu.Unlock() |
| 16 | |
| 17 | if stopNotifications != nil { |
| 18 | stopNotifications() |
| 19 | } |
| 20 | if cancelRefresh != nil { |
| 21 | cancelRefresh() |
| 22 | } |
| 23 | c.surfaceStopsMu.Lock() |
| 24 | surfaceStops := append([]func(){}, c.surfaceStops...) |
| 25 | c.surfaceStops = nil |
| 26 | c.surfaceStopsMu.Unlock() |
| 27 | for _, stop := range surfaceStops { |
| 28 | stop() |
| 29 | } |
| 30 | if c.t != nil { |
| 31 | c.t.close() |
| 32 | } |
| 33 | }) |
| 34 | } |
| 35 |