mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
feat(auth): enhance watcher with asynchronous dispatch and buffering
- Added async dispatch loop to `Watcher` for handling incremental `AuthUpdate` with in-memory buffering. - Improved resilience against high-frequency auth changes by coalescing updates and reducing redundant processing. - Updated `cliproxy` service to increase auth update queue capacity and optimize backlog consumption. - Added detailed SDK integration documentation in English and Chinese (`sdk-watcher.md`, `sdk-watcher_CN.md`).
This commit is contained in:
@@ -78,7 +78,7 @@ func (s *Service) ensureAuthUpdateQueue(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
if s.authUpdates == nil {
|
||||
s.authUpdates = make(chan watcher.AuthUpdate, 64)
|
||||
s.authUpdates = make(chan watcher.AuthUpdate, 256)
|
||||
}
|
||||
if s.authQueueStop != nil {
|
||||
return
|
||||
@@ -98,6 +98,14 @@ func (s *Service) consumeAuthUpdates(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
s.handleAuthUpdate(ctx, update)
|
||||
for {
|
||||
select {
|
||||
case nextUpdate := <-s.authUpdates:
|
||||
s.handleAuthUpdate(ctx, nextUpdate)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user