@@ -32,11 +32,11 @@ const (
32
32
maxPriority = math .MaxInt32
33
33
// sendMessageDebounce is the debounce duration when calling sendMessage()
34
34
sendMessageDebounce = time .Millisecond
35
- // when we reach sendMessaageCuttoff wants/cancels, we'll send the message immediately.
36
- sendMessageCuttoff = 100
35
+ // when we reach sendMessageCutoff wants/cancels, we'll send the message immediately.
36
+ sendMessageCutoff = 256
37
37
// when we debounce for more than sendMessageMaxDelay, we'll send the
38
38
// message immediately.
39
- sendMessageMaxDelay = 100 * time .Millisecond
39
+ sendMessageMaxDelay = 20 * time .Millisecond
40
40
)
41
41
42
42
// MessageNetwork is any network that can connect peers and generate a message
@@ -286,6 +286,8 @@ func (mq *MessageQueue) runQueue() {
286
286
// Create a timer for debouncing scheduled work.
287
287
scheduleWork := time .NewTimer (0 )
288
288
if ! scheduleWork .Stop () {
289
+ // Need to drain the timer if Stop() returns false
290
+ // See: https://golang.org/pkg/time/#Timer.Stop
289
291
<- scheduleWork .C
290
292
}
291
293
@@ -302,12 +304,13 @@ func (mq *MessageQueue) runQueue() {
302
304
if workScheduled .IsZero () {
303
305
workScheduled = when
304
306
} else if ! scheduleWork .Stop () {
307
+ // Need to drain the timer if Stop() returns false
305
308
<- scheduleWork .C
306
309
}
307
310
308
311
// If we have too many updates and/or we've waited too
309
312
// long, send immediately.
310
- if mq .pendingWorkCount () > sendMessageCuttoff ||
313
+ if mq .pendingWorkCount () > sendMessageCutoff ||
311
314
time .Since (workScheduled ) >= sendMessageMaxDelay {
312
315
mq .sendIfReady ()
313
316
workScheduled = time.Time {}
0 commit comments