]> 127.0.0.1 Git - part/.git/commitdiff
refine the define of limit v0.5.24
authorqydysky <qydysky@foxmail.com>
Sat, 12 Jun 2021 16:07:03 +0000 (00:07 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 12 Jun 2021 16:07:03 +0000 (00:07 +0800)
limit/Limit.go

index 9d9a4e373af48342d39d31203afe5108f164be4a..fcc0e230fd680f0ccc1562b6acf2c8c32038d2c4 100644 (file)
@@ -16,6 +16,7 @@ type Limit struct {
 
 // create a Limit Object
 // it will allow maxNum_in_period requests(call TO()) in ms_in_period. if the request(call TO()) is out of maxNum_in_period,it will wait ms_to_timeout
+//ms_to_timeout [>0:will wait ms] [=0:no wait] [<0:will block]
 func New(maxNum_in_period,ms_in_period,ms_to_timeout int) (*Limit) {
        object := Limit{
                maxNum_in_period:maxNum_in_period,
@@ -50,7 +51,7 @@ func (l *Limit) TO() bool {
        var AfterMS = func(ReadTimeout int) (c <-chan time.Time) {
                if ReadTimeout > 0 {
                        c = time.NewTimer(time.Millisecond*time.Duration(ReadTimeout)).C
-               } else if ReadTimeout < 0 {
+               } else if ReadTimeout == 0 {
                        tc := make(chan time.Time,1)
                        tc <- time.Now()
                        close(tc)