tradePairIterator: iterator,
workerNum: workerNum,
workerNumCh: make(chan int, workerNum),
- processCh: make(chan *matchTxResult, 32),
+ processCh: make(chan *matchTxResult),
tradePairCh: make(chan *common.TradePair, workerNum),
closeCh: make(chan struct{}),
gasLeft: gasLeft,
defer close(m.closeCh)
var matchedTxs []*types.Tx
- appendMatchedTxs := func(data *matchTxResult) bool {
- gasUsed := calcMatchedTxGasUsed(data.matchedTx)
- if m.gasLeft -= gasUsed; m.gasLeft >= 0 {
- matchedTxs = append(matchedTxs, data.matchedTx)
- return false
- }
- return true
- }
-
completed := 0
for !m.isTimeout() {
select {
return nil, data.err
}
- if done := appendMatchedTxs(data); done {
+ gasUsed := calcMatchedTxGasUsed(data.matchedTx)
+ if m.gasLeft -= gasUsed; m.gasLeft >= 0 {
+ matchedTxs = append(matchedTxs, data.matchedTx)
+ } else {
return matchedTxs, nil
}
case <-m.workerNumCh:
if completed++; completed == m.workerNum {
- // read the remaining process results
- close(m.processCh)
- for data := range m.processCh {
- if data.err != nil {
- return nil, data.err
- }
-
- appendMatchedTxs(data)
- }
return matchedTxs, nil
}
}