Added thread safe each

This commit is contained in:
obscuren
2015-04-04 20:34:10 +02:00
parent eff6a43419
commit c39484bc4b
2 changed files with 15 additions and 4 deletions

View File

@ -88,3 +88,14 @@ func (bc *BlockCache) Has(hash common.Hash) bool {
_, ok := bc.blocks[hash]
return ok
}
func (bc *BlockCache) Each(cb func(int, *types.Block)) {
bc.mu.Lock()
defer bc.mu.Unlock()
i := 0
for _, block := range bc.blocks {
cb(i, block)
i++
}
}