-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(grpc): extract fullChan as a full burst limiter
- Loading branch information
Showing
3 changed files
with
37 additions
and
34 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
third_party/google.golang.org/grpc/interceptors/burstlimit/burstlimit.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2024 The searKing Author. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package burstlimit | ||
|
||
// fullChan returns a channel of the given size, filled with empty structs. | ||
// simple, but effective. | ||
// | ||
// Also see: https://github.com/searKing/golang/blob/go/v1.2.118/go/time/rate/rate.go#L87 | ||
func fullChan(b int) (limiter chan struct{}) { | ||
if b > 0 { | ||
limiter = make(chan struct{}, b) | ||
for i := 0; i < b; i++ { | ||
limiter <- struct{}{} | ||
} | ||
} | ||
return limiter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters