Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
fix: make sure to iterate in case import is replicating
Browse files Browse the repository at this point in the history
  • Loading branch information
tchardin committed Oct 27, 2021
1 parent 0cdd05e commit 0be7876
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions cmd/pop/cli/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func runImport(ctx context.Context, args []string) error {
c, cc, ctx, cancel := connect(ctx)
defer cancel()

irc := make(chan *node.ImportResult, 1)
irc := make(chan *node.ImportResult, 6)
cc.SetNotifyCallback(func(n node.Notify) {
if ir := n.ImportResult; ir != nil {
irc <- ir
Expand All @@ -45,15 +45,24 @@ func runImport(ctx context.Context, args []string) error {
go receive(ctx, cc, c)

cc.Import(&node.ImportArgs{Path: args[0], CacheRF: importArgs.cacheRF})
select {
case ir := <-irc:
if ir.Err != "" {
return errors.New(ir.Err)
}

fmt.Println("Imported car with roots", ir.Roots)
return nil
case <-ctx.Done():
return ctx.Err()
for {
select {
case ir := <-irc:
if ir.Err != "" {
return errors.New(ir.Err)
}

if len(ir.Caches) > 0 {
fmt.Printf("Cached by %s\n", ir.Caches)
}

if len(ir.Roots) > 0 {
fmt.Println("Imported car with roots", ir.Roots)
return nil
}
case <-ctx.Done():
return ctx.Err()
}
}
}

0 comments on commit 0be7876

Please sign in to comment.