mirror of
https://github.com/openziti/zrok.git
synced 2025-02-02 11:29:50 +01:00
looper skeleton (#40)
This commit is contained in:
parent
37c1de1103
commit
00c0328661
@ -1,13 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import (
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(newRun().cmd)
|
rootCmd.AddCommand(newRun().cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
type run struct {
|
type run struct {
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
|
loopers int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRun() *run {
|
func newRun() *run {
|
||||||
@ -18,8 +22,36 @@ func newRun() *run {
|
|||||||
}
|
}
|
||||||
r := &run{cmd: cmd}
|
r := &run{cmd: cmd}
|
||||||
cmd.Run = r.run
|
cmd.Run = r.run
|
||||||
|
cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *run) run(_ *cobra.Command, _ []string) {
|
func (r *run) run(_ *cobra.Command, _ []string) {
|
||||||
|
var loopers []*looper
|
||||||
|
for i := 0; i < r.loopers; i++ {
|
||||||
|
l := newLooper(i)
|
||||||
|
loopers = append(loopers, l)
|
||||||
|
go l.run()
|
||||||
|
}
|
||||||
|
for _, l := range loopers {
|
||||||
|
<-l.done
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type looper struct {
|
||||||
|
id int
|
||||||
|
done chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLooper(id int) *looper {
|
||||||
|
return &looper{
|
||||||
|
id: id,
|
||||||
|
done: make(chan struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *looper) run() {
|
||||||
|
logrus.Infof("starting #%d", l.id)
|
||||||
|
defer close(l.done)
|
||||||
|
defer logrus.Infof("stopping #%d", l.id)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user