mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
core/txindexer : add wait group
This commit is contained in:
parent
141968a48b
commit
db3e02e921
1 changed files with 7 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ package core
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
|
|
@ -54,6 +55,8 @@ type txIndexer struct {
|
||||||
progress chan chan TxIndexProgress
|
progress chan chan TxIndexProgress
|
||||||
term chan chan struct{}
|
term chan chan struct{}
|
||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
|
|
||||||
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTxIndexer initializes the transaction indexer.
|
// newTxIndexer initializes the transaction indexer.
|
||||||
|
|
@ -66,6 +69,7 @@ func newTxIndexer(limit uint64, chain *BlockChain) *txIndexer {
|
||||||
term: make(chan chan struct{}),
|
term: make(chan chan struct{}),
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
indexer.wg.Add(1)
|
||||||
go indexer.loop(chain)
|
go indexer.loop(chain)
|
||||||
|
|
||||||
var msg string
|
var msg string
|
||||||
|
|
@ -199,6 +203,7 @@ func (indexer *txIndexer) repair(head uint64) {
|
||||||
// on the received chain event.
|
// on the received chain event.
|
||||||
func (indexer *txIndexer) loop(chain *BlockChain) {
|
func (indexer *txIndexer) loop(chain *BlockChain) {
|
||||||
defer close(indexer.closed)
|
defer close(indexer.closed)
|
||||||
|
defer indexer.wg.Done()
|
||||||
|
|
||||||
// Listening to chain events and manipulate the transaction indexes.
|
// Listening to chain events and manipulate the transaction indexes.
|
||||||
var (
|
var (
|
||||||
|
|
@ -306,4 +311,6 @@ func (indexer *txIndexer) close() {
|
||||||
<-ch
|
<-ch
|
||||||
case <-indexer.closed:
|
case <-indexer.closed:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
indexer.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue