MCPcopy Index your code
hub / github.com/github/copilot-sdk / On

Method On

go/session.go:547–567  ·  view source on GitHub ↗

On subscribes to events from this session. Events include assistant messages, tool executions, errors, and session state changes. Multiple handlers can be registered and will all receive events. Handlers are called synchronously in the order they were registered. The returned function can be calle

(handler SessionEventHandler)

Source from the content-addressed store, hash-verified

545// // Later, to stop receiving events:
546// unsubscribe()
547func (s *Session) On(handler SessionEventHandler) func() {
548 s.handlerMutex.Lock()
549 defer s.handlerMutex.Unlock()
550
551 id := s.nextHandlerID
552 s.nextHandlerID++
553 s.handlers = append(s.handlers, sessionHandler{id: id, fn: handler})
554
555 // Return unsubscribe function
556 return func() {
557 s.handlerMutex.Lock()
558 defer s.handlerMutex.Unlock()
559
560 for i, h := range s.handlers {
561 if h.id == id {
562 s.handlers = append(s.handlers[:i], s.handlers[i+1:]...)
563 break
564 }
565 }
566 }
567}
568
569// registerTools registers tool handlers for this session.
570//

Callers 1

SendAndWaitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected