feat: wake reconciled sessions for queued dispatch
This commit is contained in:
@@ -231,6 +231,7 @@ type Handle struct {
|
||||
SessionID [16]byte
|
||||
Generation uint64
|
||||
Context context.Context
|
||||
wake chan struct{}
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
@@ -253,11 +254,45 @@ func (registry *Registry) Install(clientID string, sessionID [16]byte, generatio
|
||||
old.cancel()
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
handle := &Handle{ClientID: clientID, SessionID: sessionID, Generation: generation, Context: ctx, cancel: cancel}
|
||||
handle := &Handle{ClientID: clientID, SessionID: sessionID, Generation: generation, Context: ctx, wake: make(chan struct{}, 1), cancel: cancel}
|
||||
registry.clients[clientID] = handle
|
||||
return handle, nil
|
||||
}
|
||||
|
||||
// Wake requests a best-effort dispatch pass for the current generation. The
|
||||
// signal is edge-triggered and coalesced; durable queue state is the source of
|
||||
// truth, so dropping a redundant wake cannot lose work.
|
||||
func (registry *Registry) Wake(clientID string) bool {
|
||||
if registry == nil || clientID == "" {
|
||||
return false
|
||||
}
|
||||
registry.mu.Lock()
|
||||
handle := registry.clients[clientID]
|
||||
registry.mu.Unlock()
|
||||
if handle == nil {
|
||||
return false
|
||||
}
|
||||
handle.SignalDispatch()
|
||||
return true
|
||||
}
|
||||
|
||||
func (handle *Handle) DispatchWake() <-chan struct{} {
|
||||
if handle == nil {
|
||||
return nil
|
||||
}
|
||||
return handle.wake
|
||||
}
|
||||
|
||||
func (handle *Handle) SignalDispatch() {
|
||||
if handle == nil || handle.wake == nil {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case handle.wake <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (registry *Registry) Remove(handle *Handle) bool {
|
||||
if handle == nil {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user