Skip to content

Commit

Permalink
chore: cleanup hello world
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <christian@aperture.us>
  • Loading branch information
paralin committed Jan 24, 2024
1 parent aac4422 commit 01bee51
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions example/hello-world/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ package main

import (
"context"
"os"

"github.com/aperturerobotics/controllerbus/bus/inmem"
"github.com/aperturerobotics/controllerbus/controller/loader"
cdc "github.com/aperturerobotics/controllerbus/directive/controller"
"github.com/sirupsen/logrus"
)

func execToy() {
func main() {
if err := execToy(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}

func execToy() error {
ctx := context.Background()
log := logrus.New()
log.SetLevel(logrus.DebugLevel)
Expand All @@ -21,16 +29,20 @@ func execToy() {
// Loader controller constructs and executes controllers
cl, err := loader.NewController(le, b)
if err != nil {
panic(err)
return err
}

// Execute the loader controller, it never exits.
go func() {
_ = b.ExecuteController(ctx, cl)
}()
// Execute the loader controller
releaseCl, err := b.AddController(ctx, cl, nil)
if err != nil {
return err
}
// releaseCl() would remove the loader controller
defer releaseCl()

le.Debug("loader controller attached")

// Issue load directive for toy controller.
// Issue directive to run the toy controller.
loadToy := loader.NewExecController(NewToyFactory(), &ToyControllerConfig{
Name: "world",
})
Expand All @@ -43,8 +55,6 @@ func execToy() {
tc := ctrl.(*ToyController)
le.Debug("toy controller resolved")
tc.SayHello()
}

func main() {
execToy()
return nil
}

0 comments on commit 01bee51

Please sign in to comment.