You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
6 years ago
|
package blockproposal
|
||
6 years ago
|
|
||
|
import (
|
||
|
"github.com/harmony-one/harmony/internal/utils"
|
||
|
)
|
||
|
|
||
|
// Service is the new block service.
|
||
|
type Service struct {
|
||
6 years ago
|
stopChan chan struct{}
|
||
|
stoppedChan chan struct{}
|
||
|
readySignal chan struct{}
|
||
|
waitForConsensusReady func(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})
|
||
6 years ago
|
}
|
||
|
|
||
|
// NewService returns new block service.
|
||
6 years ago
|
func NewService(readySignal chan struct{}, waitForConsensusReady func(readySignal chan struct{}, stopChan chan struct{}, stoppedChan chan struct{})) *Service {
|
||
|
return &Service{readySignal: readySignal, waitForConsensusReady: waitForConsensusReady}
|
||
6 years ago
|
}
|
||
|
|
||
|
// StartService starts new block service.
|
||
|
func (s *Service) StartService() {
|
||
|
s.stopChan = make(chan struct{})
|
||
|
s.stoppedChan = make(chan struct{})
|
||
|
|
||
|
s.Init()
|
||
|
s.Run(s.stopChan, s.stoppedChan)
|
||
|
}
|
||
|
|
||
|
// Init initializes new block service.
|
||
|
func (s *Service) Init() {
|
||
|
}
|
||
|
|
||
|
// Run runs new block.
|
||
|
func (s *Service) Run(stopChan chan struct{}, stoppedChan chan struct{}) {
|
||
6 years ago
|
s.waitForConsensusReady(s.readySignal, s.stopChan, s.stoppedChan)
|
||
6 years ago
|
}
|
||
|
|
||
|
// StopService stops new block service.
|
||
|
func (s *Service) StopService() {
|
||
|
utils.GetLogInstance().Info("Stopping new block service.")
|
||
|
s.stopChan <- struct{}{}
|
||
|
<-s.stoppedChan
|
||
|
utils.GetLogInstance().Info("Role conversion stopped.")
|
||
|
}
|