MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / withQueueMutationLock

Function withQueueMutationLock

apps/kimi-code/src/tui/goal-queue-store.ts:176–195  ·  view source on GitHub ↗
(
  session: GoalQueueSession,
  work: () => Promise<T>,
)

Source from the content-addressed store, hash-verified

174}
175
176async function withQueueMutationLock<T>(
177 session: GoalQueueSession,
178 work: () => Promise<T>,
179): Promise<T> {
180 const filePath = goalQueuePath(session);
181 const previous = queueMutationLocks.get(filePath) ?? Promise.resolve();
182 const run = previous.catch(() => undefined).then(work);
183 const lock = run.then(
184 () => undefined,
185 () => undefined,
186 );
187 queueMutationLocks.set(filePath, lock);
188 try {
189 return await run;
190 } finally {
191 if (queueMutationLocks.get(filePath) === lock) {
192 queueMutationLocks.delete(filePath);
193 }
194 }
195}
196
197function emptyQueueFile(): GoalQueueFile {
198 return { version: GOAL_QUEUE_VERSION, goals: [] };

Callers 5

appendGoalQueueItemFunction · 0.85
updateGoalQueueItemFunction · 0.85
removeGoalQueueItemFunction · 0.85
restoreGoalQueueItemFunction · 0.85
moveGoalQueueItemFunction · 0.85

Calls 5

goalQueuePathFunction · 0.85
getMethod · 0.65
resolveMethod · 0.65
setMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected