storage/backend: remove startc var

This makes start logic cleaner.
This commit is contained in:
Yicheng Qin 2015-08-27 22:59:14 -07:00
parent f04884f74d
commit 054fab84ee

View File

@ -22,9 +22,8 @@ type backend struct {
batchLimit int batchLimit int
batchTx *batchTx batchTx *batchTx
stopc chan struct{} stopc chan struct{}
startc chan struct{} donec chan struct{}
donec chan struct{}
} }
func New(path string, d time.Duration, limit int) Backend { func New(path string, d time.Duration, limit int) Backend {
@ -40,13 +39,12 @@ func New(path string, d time.Duration, limit int) Backend {
batchLimit: limit, batchLimit: limit,
batchTx: &batchTx{}, batchTx: &batchTx{},
stopc: make(chan struct{}), stopc: make(chan struct{}),
startc: make(chan struct{}), donec: make(chan struct{}),
donec: make(chan struct{}),
} }
b.batchTx.backend = b b.batchTx.backend = b
b.batchTx.Commit()
go b.run() go b.run()
<-b.startc
return b return b
} }
@ -73,9 +71,6 @@ func (b *backend) Snapshot(w io.Writer) (n int64, err error) {
func (b *backend) run() { func (b *backend) run() {
defer close(b.donec) defer close(b.donec)
b.batchTx.Commit()
b.startc <- struct{}{}
for { for {
select { select {
case <-time.After(b.batchInterval): case <-time.After(b.batchInterval):