MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / makeFlushLock

Function makeFlushLock

packages/cloudflare/src/flush.ts:51–81  ·  view source on GitHub ↗
(context: ExecutionContext)

Source from the content-addressed store, hash-verified

49 * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.
50 */
51export function makeFlushLock(context: ExecutionContext): FlushLock {
52 const registry = getOrCreateFlushLockRegistry(context);
53 let resolveAllDone: () => void = () => undefined;
54 const allDone = new Promise<void>(res => {
55 resolveAllDone = res;
56 });
57 let pending = 0;
58
59 const lock: FlushLockInternal = {
60 ready: allDone,
61 acquire: () => {
62 pending++;
63 },
64 release: () => {
65 if (--pending === 0) {
66 registry.locks.delete(lock);
67 resolveAllDone();
68 }
69 },
70 finalize: () => {
71 if (pending === 0) {
72 registry.locks.delete(lock);
73 resolveAllDone();
74 }
75 return allDone;
76 },
77 };
78
79 registry.locks.add(lock);
80 return Object.freeze(lock);
81}
82
83function getOrCreateFlushLockRegistry(context: ExecutionContext): FlushLockRegistry {
84 // eslint-disable-next-line @typescript-eslint/unbound-method

Callers 3

flush.test.tsFile · 0.90
client.test.tsFile · 0.90
initFunction · 0.90

Calls 5

resolveAllDoneFunction · 0.85
freezeMethod · 0.80
deleteMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected