mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-05 04:58:33 +02:00
Prepare using a context for export / import
This will allow cancelling the export if the import fails before the export finished. For now the context isn't passed on to the actual export functions, hence there is not yet any cancellation happening.
This commit is contained in:
parent
536fae6a46
commit
3b545a0fd6
3 changed files with 37 additions and 16 deletions
|
@ -16,6 +16,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
@ -113,16 +114,22 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
|||
progressChan := make(chan models.TransferProgress)
|
||||
progress := setupProgressBars(progressChan)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
// Export from source
|
||||
exportChan := make(chan R, 1000)
|
||||
go exp.Process(wg, timestamp, exportChan, progressChan)
|
||||
go exp.Process(ctx, wg, timestamp, exportChan, progressChan)
|
||||
|
||||
// Import into target
|
||||
resultChan := make(chan models.ImportResult)
|
||||
go imp.Process(wg, exportChan, resultChan, progressChan)
|
||||
go imp.Process(ctx, wg, exportChan, resultChan, progressChan)
|
||||
result := <-resultChan
|
||||
|
||||
// Once import is done, the context can be cancelled
|
||||
cancel()
|
||||
|
||||
// Wait for all goroutines to finish
|
||||
wg.Wait()
|
||||
progress.close()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue