code clean-up; use standardized Run... functions for async calls
This commit is contained in:
parent
7d8d9abe54
commit
bcbf567a7a
3 changed files with 16 additions and 14 deletions
|
@ -27,7 +27,19 @@ type Context interface {
|
||||||
WaitGroup() *sync.WaitGroup
|
WaitGroup() *sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
type StartFct = func(Context)
|
type FctCtx = func(Context)
|
||||||
|
|
||||||
|
type StartFct = FctCtx
|
||||||
|
|
||||||
|
// async Runners
|
||||||
|
|
||||||
|
func RunCtx(ctx Context, fct FctCtx) {
|
||||||
|
ctx.WaitGroup().Add(1)
|
||||||
|
go func() {
|
||||||
|
defer ctx.WaitGroup().Done()
|
||||||
|
fct(ctx)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
// Context implementation
|
// Context implementation
|
||||||
|
|
||||||
|
|
14
scopes.go
14
scopes.go
|
@ -17,27 +17,17 @@ type Cfg struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(ctx common.Context) {
|
func Start(ctx common.Context) {
|
||||||
ctx.WaitGroup().Add(1)
|
common.RunCtx(ctx, start)
|
||||||
go func() {
|
|
||||||
start(ctx)
|
|
||||||
ctx.WaitGroup().Done()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(ctx common.Context) {
|
func start(ctx common.Context) {
|
||||||
|
defer close(ctx.Done())
|
||||||
for _, cfg := range ctx.Config().Children() {
|
for _, cfg := range ctx.Config().Children() {
|
||||||
cctx := ctx.ChildContext(cfg)
|
cctx := ctx.ChildContext(cfg)
|
||||||
cfg.Starter()(cctx)
|
cfg.Starter()(cctx)
|
||||||
fmt.Println(cfg.Name(), " started")
|
fmt.Println(cfg.Name(), " started")
|
||||||
}
|
}
|
||||||
fmt.Println("running ", ctx.WaitGroup())
|
fmt.Println("running ", ctx.WaitGroup())
|
||||||
defer func() {
|
|
||||||
close(ctx.Done())
|
|
||||||
fmt.Println("finishing #1 ", ctx.WaitGroup())
|
|
||||||
//ctx.WaitGroup().Wait()
|
|
||||||
//fmt.Println("finishing #2 ", ctx.WaitGroup())
|
|
||||||
//ctx.LogDebug("Dispatcher exited", m.Map{})
|
|
||||||
}()
|
|
||||||
sig := make(chan os.Signal, 1)
|
sig := make(chan os.Signal, 1)
|
||||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||||
for step(ctx, sig) {
|
for step(ctx, sig) {
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
|
|
||||||
func Start(ctx common.Context) {
|
func Start(ctx common.Context) {
|
||||||
scopes.Start(ctx)
|
scopes.Start(ctx)
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// definitions
|
// definitions
|
||||||
|
@ -41,6 +40,7 @@ func SetUpApp(tbase *testing.T, cfg common.Config) *T {
|
||||||
t := SetUp(tbase)
|
t := SetUp(tbase)
|
||||||
t.Ctx = common.AppContext(cfg)
|
t.Ctx = common.AppContext(cfg)
|
||||||
cfg.Starter()(t.Ctx)
|
cfg.Starter()(t.Ctx)
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue