aboutsummaryrefslogtreecommitdiffstats
path: root/cache/multi_repo_cache.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-12-27 19:39:09 +0100
committerMichael Muré <batolettre@gmail.com>2022-12-27 19:39:09 +0100
commitb27958758fe59f3c984243f4ad3cb8bcb4f43e86 (patch)
treed04c5e9b3baf91a14c32aa742938ada718f07914 /cache/multi_repo_cache.go
parent8cea6c7515e42cb8821a03c9bfebb0a8f63a01be (diff)
downloadgit-bug-b27958758fe59f3c984243f4ad3cb8bcb4f43e86.tar.gz
cache: simplify cache building events handling
Diffstat (limited to 'cache/multi_repo_cache.go')
-rw-r--r--cache/multi_repo_cache.go37
1 files changed, 21 insertions, 16 deletions
diff --git a/cache/multi_repo_cache.go b/cache/multi_repo_cache.go
index 007737ad..da9544cf 100644
--- a/cache/multi_repo_cache.go
+++ b/cache/multi_repo_cache.go
@@ -21,25 +21,30 @@ func NewMultiRepoCache() *MultiRepoCache {
}
// RegisterRepository register a named repository. Use this for multi-repo setup
-func (c *MultiRepoCache) RegisterRepository(name string, repo repository.ClockedRepo) (*RepoCache, chan BuildEvent, error) {
- r, events, err := NewNamedRepoCache(repo, name)
- if err != nil {
- return nil, nil, err
- }
+func (c *MultiRepoCache) RegisterRepository(repo repository.ClockedRepo, name string) (*RepoCache, chan BuildEvent) {
+ r, events := NewNamedRepoCache(repo, name)
- c.repos[name] = r
- return r, events, nil
-}
+ // intercept events to make sure the cache building process succeed properly
+ out := make(chan BuildEvent)
+ go func() {
+ defer close(out)
-// RegisterDefaultRepository register an unnamed repository. Use this for mono-repo setup
-func (c *MultiRepoCache) RegisterDefaultRepository(repo repository.ClockedRepo) (*RepoCache, chan BuildEvent, error) {
- r, events, err := NewRepoCache(repo)
- if err != nil {
- return nil, nil, err
- }
+ for event := range events {
+ out <- event
+ if event.Err != nil {
+ return
+ }
+ }
+
+ c.repos[name] = r
+ }()
+
+ return r, out
+}
- c.repos[defaultRepoName] = r
- return r, events, nil
+// RegisterDefaultRepository register an unnamed repository. Use this for single-repo setup
+func (c *MultiRepoCache) RegisterDefaultRepository(repo repository.ClockedRepo) (*RepoCache, chan BuildEvent) {
+ return c.RegisterRepository(repo, defaultRepoName)
}
// DefaultRepo retrieve the default repository