MCPcopy Index your code
hub / github.com/codeaashu/claude-code / withStatsCacheLock

Function withStatsCacheLock

src/utils/statsCache.ts:27–46  ·  view source on GitHub ↗
(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

25 * Only one operation can hold the lock at a time.
26 */
27export async function withStatsCacheLock<T>(fn: () => Promise<T>): Promise<T> {
28 // Wait for any existing lock to be released
29 while (statsCacheLockPromise) {
30 await statsCacheLockPromise
31 }
32
33 // Create our lock
34 let releaseLock: (() => void) | undefined
35 statsCacheLockPromise = new Promise<void>(resolve => {
36 releaseLock = resolve
37 })
38
39 try {
40 return await fn()
41 } finally {
42 // Release the lock
43 statsCacheLockPromise = null
44 releaseLock?.()
45 }
46}
47
48/**
49 * Persisted stats cache stored on disk.

Callers 1

aggregateClaudeCodeStatsFunction · 0.85

Calls 1

releaseLockFunction · 0.85

Tested by

no test coverage detected