Repository navigation
Introduce transfer queue options #1746
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,16 +115,24 @@ type TransferQueue struct { | |
| rc *retryCounter | ||
| } | ||
|
|
||
| // newTransferQueue builds a TransferQueue, direction and underlying mechanism determined by adapter | ||
| func newTransferQueue(dir transfer.Direction, meter progress.Meter, dryRun bool) *TransferQueue { | ||
| if meter == nil { | ||
| meter = progress.Noop() | ||
| type TransferQueueOption func(*TransferQueue) | ||
|
|
||
| func DryRun(dryRun bool) TransferQueueOption { | ||
| return func(tq *TransferQueue) { | ||
| tq.dryRun = dryRun | ||
| } | ||
| } | ||
|
|
||
| func WithProgress(m progress.Meter) TransferQueueOption { | ||
| return func(tq *TransferQueue) { | ||
| tq.meter = m | ||
| } | ||
| } | ||
|
|
||
| // newTransferQueue builds a TransferQueue, direction and underlying mechanism determined by adapter | ||
| func newTransferQueue(dir transfer.Direction, options ...TransferQueueOption) *TransferQueue { | ||
| q := &TransferQueue{ | ||
| direction: dir, | ||
| dryRun: dryRun, | ||
| meter: meter, | ||
| retriesc: make(chan Transferable, batchSize), | ||
| errorc: make(chan error), | ||
| transferables: make(map[string]Transferable), | ||
|
|
@@ -133,6 +141,14 @@ func newTransferQueue(dir transfer.Direction, meter progress.Meter, dryRun bool) | |
| rc: newRetryCounter(config.Config), | ||
| } | ||
|
|
||
| for _, opt := range options { | ||
| opt(q) | ||
| } | ||
|
|
||
| if q.meter == nil { | ||
| q.meter = progress.Noop() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: assign this in the struct initialization. That'll remove this conditional.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'll remove the conditional, but it'll also create a dummy struct that we never need when the |
||
| } | ||
|
|
||
| q.errorwait.Add(1) | ||
| q.retrywait.Add(1) | ||
| q.run() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😻 I love the
options ...TransferQueueOptionpattern.