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

Method On

go/client.go:1456–1471  ·  view source on GitHub ↗

On subscribes to all session lifecycle events. Lifecycle events are emitted when sessions are created, deleted, updated, or change foreground/background state (in TUI+server mode). Returns a function that, when called, unsubscribes the handler. Example: unsubscribe := client.On(func(event copil

(handler SessionLifecycleHandler)

Source from the content-addressed store, hash-verified

1454// })
1455// defer unsubscribe()
1456func (c *Client) On(handler SessionLifecycleHandler) func() {
1457 c.lifecycleHandlersMux.Lock()
1458 if c.lifecycleHandlers == nil {
1459 c.lifecycleHandlers = make(map[uint64]SessionLifecycleHandler)
1460 }
1461 c.nextLifecycleHandlerID++
1462 id := c.nextLifecycleHandlerID
1463 c.lifecycleHandlers[id] = handler
1464 c.lifecycleHandlersMux.Unlock()
1465
1466 return func() {
1467 c.lifecycleHandlersMux.Lock()
1468 defer c.lifecycleHandlersMux.Unlock()
1469 delete(c.lifecycleHandlers, id)
1470 }
1471}
1472
1473// OnEventType subscribes to a specific session lifecycle event type.
1474//

Callers 15

CreateSessionMethod · 0.95
TestClientLifecycleE2EFunction · 0.95
TestSession_OnFunction · 0.45
mainFunction · 0.45
watchPermissionFunction · 0.45
watchToolFunction · 0.45
watchAssistantFunction · 0.45
TestAbortE2EFunction · 0.45
TestPendingWorkResumeE2EFunction · 0.45
TestMultiTurnE2EFunction · 0.45

Calls

no outgoing calls

Tested by 15

TestClientLifecycleE2EFunction · 0.76
TestSession_OnFunction · 0.36
TestAbortE2EFunction · 0.36
TestPendingWorkResumeE2EFunction · 0.36
TestMultiTurnE2EFunction · 0.36
TestPermissionsE2EFunction · 0.36
TestCommandsE2EFunction · 0.36
TestToolResultsE2EFunction · 0.36
TestMultiClientE2EFunction · 0.36