From 3c9995dd4a2087d1eeab32136e1d2adc8d488b38 Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 15 Aug 2016 13:49:13 -0400 Subject: [PATCH] dcrd: Do not send a wakeup if not sleeping (#314) A simple printf shows dozens of AfterFuncs being generated, especially on testnet where the connectable node count is currently low. By resetting the timer, it prevents needless wakeups from filling the channel. --- server.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server.go b/server.go index 5e953c3a..0ad2d688 100644 --- a/server.go +++ b/server.go @@ -1827,7 +1827,8 @@ func (s *server) peerHandler() { } // if nothing else happens, wake us up soon. - time.AfterFunc(10*time.Second, func() { s.wakeup <- struct{}{} }) + wakeupAfter := 10 * time.Second + timer := time.AfterFunc(wakeupAfter, func() { s.wakeup <- struct{}{} }) out: for { @@ -1946,9 +1947,7 @@ out: // We need more peers, wake up in ten seconds and try again. if state.NeedMoreOutbound() { - time.AfterFunc(10*time.Second, func() { - s.wakeup <- struct{}{} - }) + timer.Reset(wakeupAfter) } }