From 96218a3afcce56a096a159dc5bc883e3b31e4c89 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 13 Jun 2021 00:07:03 +0800 Subject: [PATCH] refine the define of limit --- limit/Limit.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) -- 2.39.2