Jobs & Workflows https://armen.surge.sh
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.
 
 
 

85 lines
1.7 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### engine ####### Copyright (c) 2021 mls-361 ################################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package engine
import (
"sync"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/mls-361/application"
"forge.chapril.org/mls-361/logger"
"forge.chapril.org/mls-361/uuid"
)
// Engine AFAIRE.
type Engine struct {
app *application.Application
cfg *config.Config
stopCh chan struct{}
endCh chan error
swg sync.WaitGroup
logger logger.Logger
}
// New AFAIRE.
func New(app *application.Application, cfg *config.Config) *Engine {
return &Engine{
app: app,
cfg: cfg,
stopCh: make(chan struct{}),
endCh: make(chan error, 1),
}
}
// ConfigHasChanged AFAIRE.
func (e *Engine) ConfigHasChanged() {}
// EndCh AFAIRE.
func (e *Engine) EndCh() <-chan error {
return e.endCh
}
// Wait AFAIRE.
func (e *Engine) Wait() {
e.swg.Wait()
}
func (e *Engine) loop() {
loop:
for {
select {
case <-e.stopCh:
break loop
}
}
e.endCh <- nil
}
func (e *Engine) main(logger logger.Logger) {
defer e.swg.Done()
defer logger.Remove()
e.logger = logger
e.loop()
}
// Start AFAIRE.
func (e *Engine) Start(logger logger.Logger) {
e.swg.Add(1)
go e.main(logger.NewLogger(uuid.New(), "engine")) //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
// Stop AFAIRE.
func (e *Engine) Stop() {
close(e.stopCh)
}
/*
######################################################################################################## @(°_°)@ #######
*/