docs(limiter/conn): add doc comments, fix nil guards and missing Close

Add package and exported symbol doc comments across conn, generator,
limiter, and wrapper packages. Fix nil receiver guard in
connLimitSingleGenerator.Limiter, add missing httpLoader.Close call,
return context.Background instead of nil in serverConn.Context, return
explicit error on connection limit exceeded, and simplify Allow logic.
This commit is contained in:
ginuerzh
2026-05-24 19:38:07 +08:00
parent 0e96f602fa
commit fa708f4b5f
5 changed files with 55 additions and 10 deletions
+6 -3
View File
@@ -12,6 +12,7 @@ type llimiter struct {
current int64
}
// NewLimiter creates a Limiter that allows up to n concurrent connections.
func NewLimiter(n int) limiter.Limiter {
return &llimiter{limit: n}
}
@@ -21,10 +22,12 @@ func (l *llimiter) Limit() int {
}
func (l *llimiter) Allow(n int) bool {
if n < 0 {
atomic.AddInt64(&l.current, int64(n))
return true
}
if atomic.AddInt64(&l.current, int64(n)) > int64(l.limit) {
if n > 0 {
atomic.AddInt64(&l.current, -int64(n))
}
atomic.AddInt64(&l.current, -int64(n))
return false
}
return true