mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
c7a10934d8
* data races * log cencelation
43 lines
729 B
Go
43 lines
729 B
Go
package consensus
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/debug"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
)
|
|
|
|
type ResultWithContext struct {
|
|
Cancel
|
|
*types.Block
|
|
}
|
|
|
|
type Cancel struct {
|
|
context.Context
|
|
cancel context.CancelFunc
|
|
}
|
|
|
|
func (c *Cancel) CancelFunc() {
|
|
log.Debug("cancel mining task", "callers", debug.Callers(10))
|
|
c.cancel()
|
|
}
|
|
|
|
func NewCancel(ctxs ...context.Context) Cancel {
|
|
var ctx context.Context
|
|
if len(ctxs) > 0 {
|
|
ctx = ctxs[0]
|
|
} else {
|
|
ctx = context.Background()
|
|
}
|
|
ctx, cancelFn := context.WithCancel(ctx)
|
|
return Cancel{ctx, cancelFn}
|
|
}
|
|
|
|
func StabCancel() Cancel {
|
|
return Cancel{
|
|
context.Background(),
|
|
func() {},
|
|
}
|
|
}
|