github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/ledger/complete/wal/fixtures/noopcompactor.go (about)

     1  package fixtures
     2  
     3  import (
     4  	"github.com/onflow/flow-go/ledger/complete"
     5  )
     6  
     7  type NoopCompactor struct {
     8  	stopCh       chan struct{}
     9  	trieUpdateCh <-chan *complete.WALTrieUpdate
    10  }
    11  
    12  func NewNoopCompactor(l *complete.Ledger) *NoopCompactor {
    13  	return &NoopCompactor{
    14  		stopCh:       make(chan struct{}),
    15  		trieUpdateCh: l.TrieUpdateChan(),
    16  	}
    17  }
    18  
    19  func (c *NoopCompactor) Ready() <-chan struct{} {
    20  	ch := make(chan struct{})
    21  	close(ch)
    22  	go c.run()
    23  	return ch
    24  }
    25  
    26  func (c *NoopCompactor) Done() <-chan struct{} {
    27  	close(c.stopCh)
    28  	return c.stopCh
    29  }
    30  
    31  func (c *NoopCompactor) run() {
    32  	for {
    33  		select {
    34  		case <-c.stopCh:
    35  			return
    36  		case update, ok := <-c.trieUpdateCh:
    37  			if !ok {
    38  				continue
    39  			}
    40  
    41  			// Send result of WAL update
    42  			update.ResultCh <- nil
    43  
    44  			// Wait for trie update
    45  			<-update.TrieCh
    46  		}
    47  	}
    48  }