waitForSession waits for a session to appear, using channel-based notification. Returns nil if the session does not appear within the timeout.
(sessionID string, timeout time.Duration)
| 280 | // waitForSession waits for a session to appear, using channel-based notification. |
| 281 | // Returns nil if the session does not appear within the timeout. |
| 282 | func (b *Bridge) waitForSession(sessionID string, timeout time.Duration) *sessions.Session { |
| 283 | if sess := sessions.Global().Get(sessionID); sess != nil { |
| 284 | return sess |
| 285 | } |
| 286 | ch, _ := b.sessionReady.LoadOrStore(sessionID, make(chan struct{})) |
| 287 | select { |
| 288 | case <-ch.(chan struct{}): |
| 289 | return sessions.Global().Get(sessionID) |
| 290 | case <-time.After(timeout): |
| 291 | log.Warnf("[bridge] waitForSession timeout for %s after %v", sessionID, timeout) |
| 292 | return nil |
| 293 | case <-b.ctx.Done(): |
| 294 | return nil |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // notifySessionReady signals any goroutines waiting for the given session. |
| 299 | func (b *Bridge) notifySessionReady(sessionID string) { |