notifySessions calls Notify on all the sessions. Should be called on a copy of the peer sessions. The logger must be non-nil.
(sessions []S, method string, params P, logger *slog.Logger)
| 397 | // Should be called on a copy of the peer sessions. |
| 398 | // The logger must be non-nil. |
| 399 | func notifySessions[S Session, P Params](sessions []S, method string, params P, logger *slog.Logger) { |
| 400 | if sessions == nil { |
| 401 | return |
| 402 | } |
| 403 | // Notify with the background context, so the messages are sent on the |
| 404 | // standalone stream. |
| 405 | // TODO: make this timeout configurable, or call handleNotify asynchronously. |
| 406 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 407 | defer cancel() |
| 408 | |
| 409 | // TODO: there's a potential spec violation here, when the feature list |
| 410 | // changes before the session (client or server) is initialized. |
| 411 | for _, s := range sessions { |
| 412 | req := newRequest(s, params) |
| 413 | if err := handleNotify(ctx, method, req); err != nil { |
| 414 | logger.Warn(fmt.Sprintf("calling %s: %v", method, err)) |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | func newRequest[S Session, P Params](s S, p P) Request { |
| 420 | switch s := any(s).(type) { |
no test coverage detected
searching dependent graphs…