From 9aa27517eb053937a03a02ef6335a2a111f6ab7e Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 4 Feb 2014 11:01:21 -0500 Subject: [PATCH] Buffer the disk syncer flush channel. --- disksync.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/disksync.go b/disksync.go index e71f523..2d5a85c 100644 --- a/disksync.go +++ b/disksync.go @@ -214,7 +214,7 @@ type DiskSyncer struct { // NewDiskSyncer creates a new DiskSyncer. func NewDiskSyncer(am *AccountManager) *DiskSyncer { return &DiskSyncer{ - flushScheduled: make(chan struct{}), + flushScheduled: make(chan struct{}, 1), flushAccount: make(chan *flushAccountRequest), scheduleWallet: make(chan *Account), scheduleTxStore: make(chan *Account), @@ -279,7 +279,13 @@ func (ds *DiskSyncer) Start() { // FlushScheduled writes all scheduled account files to disk. func (ds *DiskSyncer) FlushScheduled() { - ds.flushScheduled <- struct{}{} + // Schedule a flush if one is not already waiting. This channel + // is buffered so if a request is already waiting, a duplicate + // can be safely dropped. + select { + case ds.flushScheduled <- struct{}{}: + default: + } } // FlushAccount writes all scheduled account files to disk for a single