Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move channel write logic to manager #1445

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/oras/internal/display/status/progress/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"sync"
"time"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras/cmd/oras/internal/display/status/console"
)

Expand All @@ -39,6 +40,7 @@
// Manager is progress view master
type Manager interface {
Add() (Status, error)
SendAndStop(desc ocispec.Descriptor, prompt string) error
Close() error
}

Expand Down Expand Up @@ -120,6 +122,18 @@
return m.statusChan(s), nil
}

// SendAndStop send message for descriptor and stop timing.
func (m *manager) SendAndStop(desc ocispec.Descriptor, prompt string) error {
status, err := m.Add()
if err != nil {
return err

Check warning on line 129 in cmd/oras/internal/display/status/progress/manager.go

View check run for this annotation

Codecov / codecov/patch

cmd/oras/internal/display/status/progress/manager.go#L129

Added line #L129 was not covered by tests
}
defer close(status)
status <- NewStatusMessage(prompt, desc, desc.Size)
status <- EndTiming()
return nil
}

func (m *manager) statusChan(s *status) Status {
ch := make(chan *status, BufferSize)
m.updating.Add(1)
Expand Down
9 changes: 1 addition & 8 deletions cmd/oras/internal/display/status/track/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,5 @@ func (t *graphTarget) Close() error {

// Prompt prompts the user with the provided prompt and descriptor.
func (t *graphTarget) Prompt(desc ocispec.Descriptor, prompt string) error {
status, err := t.manager.Add()
if err != nil {
return err
}
defer close(status)
status <- progress.NewStatusMessage(prompt, desc, desc.Size)
status <- progress.EndTiming()
return nil
return t.manager.SendAndStop(desc, prompt)
}
Loading