diff --git a/cmd/zrokloop/loop.go b/cmd/zrokloop/loop.go index edaa6538..8fd1fde7 100644 --- a/cmd/zrokloop/loop.go +++ b/cmd/zrokloop/loop.go @@ -1,13 +1,17 @@ package main -import "github.com/spf13/cobra" +import ( + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) func init() { rootCmd.AddCommand(newRun().cmd) } type run struct { - cmd *cobra.Command + cmd *cobra.Command + loopers int } func newRun() *run { @@ -18,8 +22,36 @@ func newRun() *run { } r := &run{cmd: cmd} cmd.Run = r.run + cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start") return r } 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) }