Close closes the write channel, sends [DONE], and cleans up resources
()
| 348 | |
| 349 | // Close closes the write channel, sends [DONE], and cleans up resources |
| 350 | func (h *SSEHandlerCh) Close() { |
| 351 | h.lock.Lock() |
| 352 | if h.closed || !h.initialized { |
| 353 | h.lock.Unlock() |
| 354 | return |
| 355 | } |
| 356 | h.closed = true |
| 357 | |
| 358 | // Close the write channel, which will trigger [DONE] in writerLoop |
| 359 | close(h.writeCh) |
| 360 | h.lock.Unlock() |
| 361 | |
| 362 | // Wait for writer goroutine to finish (without holding the lock) |
| 363 | h.wg.Wait() |
| 364 | } |
| 365 | |
| 366 | // AI message writing methods |
| 367 |