From: qydysky Date: Sat, 12 Jun 2021 16:07:03 +0000 (+0800) Subject: refine the define of limit X-Git-Tag: v0.5.24 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=96218a3afcce56a096a159dc5bc883e3b31e4c89;p=part%2F.git refine the define of limit --- diff --git a/limit/Limit.go b/limit/Limit.go index 9d9a4e3..fcc0e23 100644 --- a/limit/Limit.go +++ b/limit/Limit.go @@ -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)