()
| 310 | } |
| 311 | |
| 312 | func (client *client) Close() error { |
| 313 | if client.Closed() { |
| 314 | // Chances are this is being called from a defer() and the error will go unobserved |
| 315 | // so we go ahead and log the event in this case. |
| 316 | Logger.Printf("Close() called on already closed client") |
| 317 | return ErrClosedClient |
| 318 | } |
| 319 | |
| 320 | // shutdown and wait for the background thread before we take the lock, to avoid races |
| 321 | close(client.closer) |
| 322 | <-client.closed |
| 323 | |
| 324 | client.lock.Lock() |
| 325 | defer client.lock.Unlock() |
| 326 | DebugLogger.Println("Closing Client") |
| 327 | |
| 328 | for _, broker := range client.brokers { |
| 329 | safeAsyncClose(broker) |
| 330 | } |
| 331 | |
| 332 | for _, broker := range client.seedBrokers { |
| 333 | safeAsyncClose(broker) |
| 334 | } |
| 335 | |
| 336 | client.brokers = nil |
| 337 | client.metadata = nil |
| 338 | client.metadataTopics = nil |
| 339 | |
| 340 | return nil |
| 341 | } |
| 342 | |
| 343 | func (client *client) Closed() bool { |
| 344 | client.lock.RLock() |
no test coverage detected