MCPcopy Create free account
hub / github.com/docker/docker-agent / load

Method load

pkg/gateway/catalog.go:112–124  ·  view source on GitHub ↗

load fetches and caches the catalog on the first call, reusing the memoized result afterwards. The first caller's context is honoured for tracing (and threads the fetch onto the program's context), but its cancellation is detached via WithoutCancel so a cancelled first caller cannot permanently cach

(ctx context.Context)

Source from the content-addressed store, hash-verified

110// cache a context-cancellation error for everyone else. On every subsequent
111// call ctx is unused — the work has already run.
112func (l *Loader) load(ctx context.Context) (Catalog, error) {
113 // Default the fetcher so a zero-value Loader degrades to the production
114 // fetch path instead of panicking inside once.Do (which would also wedge
115 // the sync.Once into a permanently-done state).
116 fetch := l.fetch
117 if fetch == nil {
118 fetch = fetchAndCache
119 }
120 l.once.Do(func() {
121 l.cached.catalog, l.cached.err = fetch(context.WithoutCancel(ctx))
122 })
123 return l.cached.catalog, l.cached.err
124}
125
126// defaultLoader backs every call site that doesn't inject its own Loader via
127// [WithLoader]. It preserves the historical behaviour of a single

Callers 1

ServerSpecFunction · 0.45

Calls 2

fetchFunction · 0.85
DoMethod · 0.65

Tested by

no test coverage detected