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

feat: track progress #852

Closed
wants to merge 15 commits into from
Prev Previous commit
Next Next commit
chore: rearrange code
Signed-off-by: Shiwei Zhang <[email protected]>
shizhMSFT committed Dec 30, 2024
commit 02bbed026da90f080a11d51b3b121738331ea195
12 changes: 6 additions & 6 deletions progress/manager.go
Original file line number Diff line number Diff line change
@@ -33,7 +33,12 @@ type Manager interface {
// ManagerFunc is an adapter to allow the use of ordinary functions as Managers.
// If f is a function with the appropriate signature, ManagerFunc(f) is a
// [Manager] that calls f.
type ManagerFunc func(ocispec.Descriptor, Status, error) error
type ManagerFunc func(desc ocispec.Descriptor, status Status, err error) error

// Close closes the manager.
func (f ManagerFunc) Close() error {
return nil
}

// Track starts tracking the progress of a descriptor.
func (f ManagerFunc) Track(desc ocispec.Descriptor) (Tracker, error) {
@@ -42,11 +47,6 @@ func (f ManagerFunc) Track(desc ocispec.Descriptor) (Tracker, error) {
}), nil
}

// Close closes the manager.
func (f ManagerFunc) Close() error {
return nil
}

// Record adds the progress of a descriptor as a single entry.
func Record(m Manager, desc ocispec.Descriptor, status Status) error {
tracker, err := m.Track(desc)
12 changes: 6 additions & 6 deletions progress/tracker.go
Original file line number Diff line number Diff line change
@@ -32,7 +32,12 @@ type Tracker interface {
// TrackerFunc is an adapter to allow the use of ordinary functions as Trackers.
// If f is a function with the appropriate signature, TrackerFunc(f) is a
// [Tracker] that calls f.
type TrackerFunc func(Status, error) error
type TrackerFunc func(status Status, err error) error

// Close closes the tracker.
func (f TrackerFunc) Close() error {
return nil
}

// Update updates the status of the descriptor.
func (f TrackerFunc) Update(status Status) error {
@@ -44,11 +49,6 @@ func (f TrackerFunc) Fail(err error) error {
return f(Status{}, err)
}

// Close closes the tracker.
func (f TrackerFunc) Close() error {
return nil
}

// Start starts tracking the transmission.
func Start(t Tracker) error {
return t.Update(Status{