2020-02-03 12:02:26 +00:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/debug"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2020-02-03 12:02:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ResultWithContext struct {
|
|
|
|
Cancel
|
|
|
|
*types.Block
|
|
|
|
}
|
|
|
|
|
|
|
|
type Cancel struct {
|
|
|
|
context.Context
|
2020-02-10 14:28:30 +00:00
|
|
|
cancel context.CancelFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cancel) CancelFunc() {
|
2021-10-05 01:14:04 +00:00
|
|
|
log.Trace("Cancel mining task", "callers", debug.Callers(10))
|
2020-02-10 14:28:30 +00:00
|
|
|
c.cancel()
|
2020-02-03 12:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {},
|
|
|
|
}
|
|
|
|
}
|