diff --git a/internal/cmd/run.go b/internal/cmd/run.go index e19e436..da120bb 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -11,6 +11,7 @@ import ( "net/url" "os" "strings" + "sync" "github.com/loveuer/esgo2dump/internal/interfaces" "github.com/loveuer/esgo2dump/internal/opt" @@ -192,17 +193,16 @@ func executeData(ctx context.Context, input, output interfaces.DumpIO) error { e2ch = make(chan error) wch = make(chan []*model.ESSource) + wg = sync.WaitGroup{} ) go func() { - defer func() { - close(wch) - close(e2ch) - }() - + wg.Add(1) if err = output.WriteData(ctx, wch); err != nil { e2ch <- err } + + wg.Done() }() log.Info("Query: got queries=%d", len(queries)) @@ -233,6 +233,10 @@ Loop: } } + close(wch) + + wg.Wait() + return nil }