The core protocol of WoopChain
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.
woop/api/service/randgen/service.go

60 lines
1.2 KiB

package randgen
import (
"github.com/harmony-one/harmony/internal/utils"
)
6 years ago
// Service is the random generation service.
type Service struct {
stopChan chan struct{}
stoppedChan chan struct{}
}
6 years ago
// NewService returns random generation service.
func NewService() *Service {
return &Service{}
}
// StartService starts random generation service.
6 years ago
func (s *Service) StartService() {
s.stopChan = make(chan struct{})
s.stoppedChan = make(chan struct{})
6 years ago
s.Init()
s.Run(s.stopChan, s.stoppedChan)
}
// Init initializes random generation.
6 years ago
func (s *Service) Init() {
}
// Run runs random generation.
6 years ago
func (s *Service) Run(stopChan chan struct{}, stoppedChan chan struct{}) {
go func() {
defer close(stoppedChan)
for {
select {
default:
utils.GetLogInstance().Info("Running random generation")
// Write some logic here.
6 years ago
s.DoRandomGeneration()
case <-stopChan:
return
}
}
}()
}
// DoRandomGeneration does random generation.
6 years ago
func (s *Service) DoRandomGeneration() {
}
// StopService stops random generation service.
6 years ago
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping random generation service.")
6 years ago
s.stopChan <- struct{}{}
<-s.stoppedChan
6 years ago
utils.GetLogInstance().Info("Random generation stopped.")
}