Wrap more comments in pkg/volume

This commit is contained in:
Paul Morie
2016-06-04 14:14:00 -04:00
parent 029b97d5a1
commit 6415c2d288
4 changed files with 34 additions and 24 deletions

View File

@@ -23,7 +23,8 @@ import (
var _ MetricsProvider = &cachedMetrics{}
// cachedMetrics represents a MetricsProvider that wraps another provider and caches the result.
// cachedMetrics represents a MetricsProvider that wraps another provider and
// caches the result.
type cachedMetrics struct {
wrapped MetricsProvider
resultError error
@@ -31,13 +32,15 @@ type cachedMetrics struct {
once cacheOnce
}
// NewCachedMetrics creates a new cachedMetrics wrapping another MetricsProvider and caching the results.
// NewCachedMetrics creates a new cachedMetrics wrapping another
// MetricsProvider and caching the results.
func NewCachedMetrics(provider MetricsProvider) MetricsProvider {
return &cachedMetrics{wrapped: provider}
}
// GetMetrics runs the wrapped metrics provider's GetMetrics methd once and
// caches the result. Will not cache result if there is an error.
// See MetricsProvider.GetMetrics
// Runs GetMetrics Once and caches the result. Will not cache result if there is an error.
func (md *cachedMetrics) GetMetrics() (*Metrics, error) {
md.once.cache(func() error {
md.resultMetrics, md.resultError = md.wrapped.GetMetrics()
@@ -46,13 +49,15 @@ func (md *cachedMetrics) GetMetrics() (*Metrics, error) {
return md.resultMetrics, md.resultError
}
// Copied from sync.Once but we don't want to cache the results if there is an error
// Copied from sync.Once but we don't want to cache the results if there is an
// error
type cacheOnce struct {
m sync.Mutex
done uint32
}
// Copied from sync.Once but we don't want to cache the results if there is an error
// Copied from sync.Once but we don't want to cache the results if there is an
// error
func (o *cacheOnce) cache(f func() error) {
if atomic.LoadUint32(&o.done) == 1 {
return