MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / withStatsCacheLock

Function withStatsCacheLock

source code/utils/statsCache.ts:29–48  ·  view source on GitHub ↗
(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

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

Callers 1

aggregateClaudeCodeStatsFunction · 0.85

Calls 1

releaseLockFunction · 0.85

Tested by

no test coverage detected