igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
29 lines (28 loc) • 898 B
JavaScript
import KeyedMutex from "./keyedMutex.js";
class FileMoveMutex extends KeyedMutex {
movedFiles = /* @__PURE__ */ new Map();
/**
* Lock an input file for the duration of a move, and remember where it was moved to.
*/
async moveFile(inputFilePath, runnable) {
return await this.runExclusiveForKey(inputFilePath, async () => {
const movedFile = this.movedFiles.get(inputFilePath);
const [result, outputFilePath] = await runnable(movedFile);
if (outputFilePath !== void 0) {
this.movedFiles.set(inputFilePath, outputFilePath);
}
return result;
});
}
/**
* Return the new location if an input file was previously moved, without waiting on any
* in-progress moves.
*/
getMovedLocationUnsafe(filePath) {
return this.movedFiles.get(filePath);
}
}
export {
FileMoveMutex as default
};
//# sourceMappingURL=fileMoveMutex.js.map