MCPcopy
hub / github.com/meteor/meteor / makeCheapPathFunction

Function makeCheapPathFunction

tools/fs/optimistic.ts:225–251  ·  view source on GitHub ↗
(
  pathFunction: (path: string) => TResult,
)

Source from the content-addressed store, hash-verified

223}
224
225function makeCheapPathFunction<TResult>(
226 pathFunction: (path: string) => TResult,
227): typeof pathFunction {
228 if (! ENABLED) {
229 return pathFunction;
230 }
231 const wrapper = wrap(pathFunction, {
232 // The maximum LRU cache size is Math.pow(2, 16) by default, but it's
233 // important to prevent eviction churn for very-frequently-called
234 // functions like optimisticStatOrNull. While it's tempting to set
235 // this limit to Infinity, increasing it by 16x comes close enough.
236 max: Math.pow(2, 20),
237 subscribe(path) {
238 let watcher: SafeWatcher | null = watch(
239 path,
240 () => wrapper.dirty(path),
241 );
242 return function () {
243 if (watcher) {
244 watcher.close();
245 watcher = null;
246 }
247 };
248 }
249 });
250 return wrapper;
251}
252
253export const optimisticStatOrNull = makeCheapPathFunction(
254 (path: string) => {

Callers 1

optimistic.tsFile · 0.85

Calls 1

wrapFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…