Address feedback

This commit is contained in:
Ilia Babanov 2024-09-23 10:20:45 +02:00
parent 75b2bcbea9
commit 5c850df92c
No known key found for this signature in database
GPG Key ID: 17E5E4BD05551A6D
3 changed files with 9 additions and 13 deletions

View File

@ -12,7 +12,7 @@ import (
)
type upload struct {
outpuHandler sync.OutputHandler
outputHandler sync.OutputHandler
}
func (m *upload) Name() string {
@ -26,19 +26,18 @@ func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
return diag.FromErr(err)
}
opts.OutputHandler = m.outpuHandler
opts.OutputHandler = m.outputHandler
sync, err := sync.New(ctx, *opts)
if err != nil {
return diag.FromErr(err)
}
defer sync.Close()
b.Files, err = sync.RunOnce(ctx)
if err != nil {
return diag.FromErr(err)
}
sync.Close()
log.Infof(ctx, "Uploaded bundle files")
return nil
}

View File

@ -134,6 +134,7 @@ func New() *cobra.Command {
if err != nil {
return err
}
defer s.Close()
if f.watch {
err = s.RunContinuous(ctx)
@ -141,7 +142,6 @@ func New() *cobra.Command {
_, err = s.RunOnce(ctx)
}
s.Close()
return err
}

View File

@ -53,8 +53,11 @@ type Sync struct {
// Synchronization progress events are sent to this event notifier.
notifier EventNotifier
outputWaitGroup *stdsync.WaitGroup
seq int
// WaitGroup is automatically created when an output handler is provided in the SyncOptions.
// Close call is required to ensure the output handler goroutine handles all events in time.
outputWaitGroup *stdsync.WaitGroup
}
// New initializes and returns a new [Sync] instance.
@ -140,12 +143,6 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
}, nil
}
func (s *Sync) Events() <-chan Event {
ch := make(chan Event, MaxRequestsInFlight)
s.notifier = &ChannelNotifier{ch}
return ch
}
func (s *Sync) Close() {
if s.notifier == nil {
return