Skip to content

Commit

Permalink
refactor: Move channel write logic to manager
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
  • Loading branch information
TerryHowe committed Jul 13, 2024
1 parent d06bb81 commit 434c752
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 13 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 @@ import (
"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 @@ type Status chan *status
// Manager is progress view master
type Manager interface {
Add() (Status, error)
Send(desc ocispec.Descriptor, prompt string) error
Close() error
}

Expand Down Expand Up @@ -120,6 +122,17 @@ func (m *manager) Add() (Status, error) {
return m.statusChan(s), nil
}

func (m *manager) Send(desc ocispec.Descriptor, prompt string) error {
status, err := m.Add()
if err != nil {
return err

Check warning on line 128 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#L128

Added line #L128 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.Send(desc, prompt)
}

0 comments on commit 434c752

Please sign in to comment.