From 8dba52dd71c2dc2f342c619e93706362797d1d2f Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 11 Jul 2015 15:51:18 +0200 Subject: [PATCH] walk: Honor close of the done channel --- walk.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/walk.go b/walk.go index 24b4a5294..304c133a5 100644 --- a/walk.go +++ b/walk.go @@ -21,7 +21,11 @@ func walkTree(repo *repository.Repository, path string, treeID backend.ID, done t, err := LoadTree(repo, treeID) if err != nil { - jobCh <- WalkTreeJob{Path: path, Error: err} + select { + case jobCh <- WalkTreeJob{Path: path, Error: err}: + case <-done: + return + } return } @@ -30,11 +34,20 @@ func walkTree(repo *repository.Repository, path string, treeID backend.ID, done if node.Type == "dir" { walkTree(repo, p, node.Subtree, done, jobCh) } else { - jobCh <- WalkTreeJob{Path: p, Node: node} + select { + case jobCh <- WalkTreeJob{Path: p, Node: node}: + case <-done: + return + } } } - jobCh <- WalkTreeJob{Path: path, Tree: t} + select { + case jobCh <- WalkTreeJob{Path: path, Tree: t}: + case <-done: + return + } + debug.Log("walkTree", "done for %q (%v)", path, treeID.Str()) }