Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: common/errors/multierror.go

Issue 1284323002: Make LazyMultiError only constructable via function (Closed) Base URL: https://github.com/luci/luci-go.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | common/errors/multierror_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/errors/multierror.go
diff --git a/common/errors/multierror.go b/common/errors/multierror.go
index df812b643251d497f1f01b0a17014acb78b28687..9c02c558f65daca0e753df73842f368b3aedd5a4 100644
--- a/common/errors/multierror.go
+++ b/common/errors/multierror.go
@@ -73,18 +73,26 @@ func MultiErrorFromErrors(ch <-chan error) error {
return ret
}
-// LazyMultiError is a lazily-constructed MultiError. You specify the target
-// MultiError size up front (as Size), and then you call Assign for each error
-// encountered, and it's potential index. The MultiError will only be allocated
-// if one of the Assign'd errors is non-nil. Similarly, Get will retrieve either
-// the allocated MultiError, or nil if no error was encountered.
+// LazyMultiError is a lazily-constructed MultiError.
+//
+// LazyMultiError is like MultiError, except that you know the ultimate size up
+// front, and then you call Assign for each error encountered, and it's
+// potential index. The underlying MultiError will only be allocated if one of
+// the Assign'd errors is non-nil. Similarly, Get will retrieve either the
+// allocated MultiError, or nil if no error was encountered.
+// Build one with NewLazy.
type LazyMultiError struct {
M-A Ruel 2015/08/12 19:13:50 Why doesn't LazyMultiError have method Error() so
dnj (Google) 2015/08/14 16:40:00 If your goal is "only constructable", then LazyMul
iannucci 2015/08/14 17:00:26 Done
sync.Mutex
- Size int
+ size int
tandrii_google 2015/08/14 08:50:36 wait, this doesn't make what CL description says.
iannucci 2015/08/14 17:00:26 done
me MultiError
}
+// NewLazyMultiError makes a new LazyMultiError of the provided size.
+func NewLazyMultiError(size int) *LazyMultiError {
+ return &LazyMultiError{size: size}
+}
+
// Assign semantically assigns the error to the given index in the MultiError.
// If the error is nil, no action is taken. Otherwise the MultiError is
// allocated to its full size (if not already), and the error assigned into it.
@@ -97,7 +105,7 @@ func (e *LazyMultiError) Assign(i int, err error) bool {
e.Lock()
defer e.Unlock()
if e.me == nil {
- e.me = make(MultiError, e.Size)
+ e.me = make(MultiError, e.size)
}
e.me[i] = err
return true
« no previous file with comments | « no previous file | common/errors/multierror_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698