(path: string, fn: () => Promise<T>)
| 78 | // share the queue. |
| 79 | const fileLocks = new Map<string, Promise<unknown>>(); |
| 80 | async 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 | |
| 93 | export function createEditTool(options: EditToolOptions): Tool<z.infer<typeof inputSchema>> { |
| 94 | const { store } = options; |
no test coverage detected