( workspaceKey: string, callback: () => T, existingLock?: DaemonRegistryMutationLock, )
| 165 | } |
| 166 | |
| 167 | function withDaemonRegistryMutationLock<T>( |
| 168 | workspaceKey: string, |
| 169 | callback: () => T, |
| 170 | existingLock?: DaemonRegistryMutationLock, |
| 171 | ): T | null { |
| 172 | if (existingLock) { |
| 173 | if (existingLock.workspaceKey !== workspaceKey) { |
| 174 | throw new Error( |
| 175 | `Daemon registry lock for ${existingLock.workspaceKey} cannot guard ${workspaceKey}`, |
| 176 | ); |
| 177 | } |
| 178 | return callback(); |
| 179 | } |
| 180 | |
| 181 | const lock = acquireDaemonRegistryMutationLock(workspaceKey); |
| 182 | if (!lock) { |
| 183 | return null; |
| 184 | } |
| 185 | |
| 186 | try { |
| 187 | return callback(); |
| 188 | } finally { |
| 189 | lock.release(); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | function entryMatchesCleanupTarget( |
| 194 | entry: DaemonRegistryEntry, |
no test coverage detected