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)
| 110 | // cache a context-cancellation error for everyone else. On every subsequent |
| 111 | // call ctx is unused — the work has already run. |
| 112 | func (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 |
no test coverage detected