taskLoop is a standalone goroutine to fetch mining task from the task channel and mine the task.
(taskCh chan *taskItem)
| 366 | |
| 367 | // taskLoop is a standalone goroutine to fetch mining task from the task channel and mine the task. |
| 368 | func (w *worker) taskLoop(taskCh chan *taskItem) { |
| 369 | defer w.wg.Done() |
| 370 | for { |
| 371 | select { |
| 372 | case ti := <-taskCh: |
| 373 | success, err := w.mineTask(ti) |
| 374 | if err != nil { |
| 375 | select { |
| 376 | case errCh <- miningError{ti.shardIdx, ti.blockNumber, err}: |
| 377 | default: |
| 378 | w.lg.Warn("Sent miningError to errCh failed", "lenOfCh", len(errCh)) |
| 379 | } |
| 380 | w.lg.Warn("Mine task fail", "shard", ti.shardIdx, "thread", ti.thread, "block", ti.blockNumber, "err", err.Error()) |
| 381 | } |
| 382 | if success { |
| 383 | w.lg.Info("Mine task success", "shard", ti.shardIdx, "thread", ti.thread, "block", ti.blockNumber) |
| 384 | } |
| 385 | case <-w.exitCh: |
| 386 | w.lg.Debug("Worker is exiting from task loop...") |
| 387 | return |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | func (w *worker) getResult() *result { |
| 393 | w.resultLock.Lock() |
no test coverage detected