2019-09-23 15:27:30 +00:00
|
|
|
package miner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-11-25 04:45:13 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
2019-09-23 15:27:30 +00:00
|
|
|
)
|
|
|
|
|
2019-11-25 04:45:13 +00:00
|
|
|
func NewTestMiner(nextCh <-chan struct{}) func(api api.FullNode) *Miner {
|
|
|
|
return func(api api.FullNode) *Miner {
|
2019-09-23 15:27:30 +00:00
|
|
|
return &Miner{
|
2019-10-09 04:38:59 +00:00
|
|
|
api: api,
|
|
|
|
waitFunc: chanWaiter(nextCh),
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 04:38:59 +00:00
|
|
|
func chanWaiter(next <-chan struct{}) func(ctx context.Context) error {
|
|
|
|
return func(ctx context.Context) error {
|
2019-09-23 15:27:30 +00:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2019-10-09 04:38:59 +00:00
|
|
|
return ctx.Err()
|
2019-09-23 15:27:30 +00:00
|
|
|
case <-next:
|
|
|
|
}
|
|
|
|
|
2019-10-09 04:38:59 +00:00
|
|
|
return nil
|
2019-09-23 15:27:30 +00:00
|
|
|
}
|
|
|
|
}
|