MCPcopy Create free account
hub / github.com/cloudflare/computer / withFileLock

Function withFileLock

packages/computer/src/tools/fs/edit.ts:80–91  ·  view source on GitHub ↗
(path: string, fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

78// share the queue.
79const fileLocks = new Map<string, Promise<unknown>>();
80async function withFileLock<T>(path: string, fn: () => Promise<T>): Promise<T> {
81 const prev = fileLocks.get(path) ?? Promise.resolve();
82 const next = prev.then(fn, fn);
83 fileLocks.set(
84 path,
85 next.finally(() => {
86 // Clear only if we're still the tail of the chain.
87 if (fileLocks.get(path) === next) fileLocks.delete(path);
88 }),
89 );
90 return next;
91}
92
93export function createEditTool(options: EditToolOptions): Tool<z.infer<typeof inputSchema>> {
94 const { store } = options;

Callers 1

createEditToolFunction · 0.85

Calls 4

resolveMethod · 0.80
getMethod · 0.65
setMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected