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

59 lines
1.2 KiB

package randgen
import (
"github.com/harmony-one/harmony/internal/utils"
)
// Service is the random generation service.
type Service struct {
stopChan chan struct{}
stoppedChan chan struct{}
}
// New returns random generation service.
func New() *Service {
return &Service{}
}
// StartService starts random generation 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 random generation.
func (s *Service) Init() {
}
// Run runs random generation.
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.
s.DoRandomGeneration()
case <-stopChan:
return
}
}
}()
}
// DoRandomGeneration does random generation.
func (s *Service) DoRandomGeneration() {
}
// StopService stops random generation service.
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping random generation service.")
s.stopChan <- struct{}{}
<-s.stoppedChan
utils.GetLogInstance().Info("Random generation stopped.")
}