Bugfix: fix race conditions
This commit is contained in:
Vendored
+11
-29
@@ -16,11 +16,19 @@ exports.default = watchFiles;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const delay_1 = __importDefault(require("../../utils/delay"));
|
||||
const sync_1 = __importDefault(require("../../utils/sync"));
|
||||
const sync_scheduler_1 = __importDefault(require("../../utils/sync-scheduler"));
|
||||
function watchFiles(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ files, options, }) {
|
||||
let timeout;
|
||||
const UPDATE_TIMEOUT = 1000;
|
||||
try {
|
||||
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval) ? options.interval : UPDATE_TIMEOUT;
|
||||
const scheduler = new sync_scheduler_1.default((filePath, firstRun) => (0, sync_1.default)({
|
||||
options,
|
||||
dirPath: filePath,
|
||||
dirs: files,
|
||||
isFiles: true,
|
||||
firstRun,
|
||||
}), INTERVAL);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
const filePath = typeof file == "string" ? file : (file === null || file === void 0 ? void 0 : file.path) ? file.path : null;
|
||||
@@ -61,23 +69,7 @@ function watchFiles(_a) {
|
||||
fs_1.default.watchFile(filePath, {
|
||||
interval: interval || 200,
|
||||
}, (curr, prev) => {
|
||||
if (global.SYNCING)
|
||||
return;
|
||||
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval)
|
||||
? options.interval
|
||||
: UPDATE_TIMEOUT;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
global.SYNCING = true;
|
||||
(0, sync_1.default)({
|
||||
options,
|
||||
dirPath: filePath,
|
||||
dirs: files,
|
||||
isFiles: true,
|
||||
}).finally(() => {
|
||||
process.exit(global.SYNC_SUCCESS_EXIT_CODE);
|
||||
});
|
||||
}, INTERVAL);
|
||||
scheduler.schedule(filePath);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -85,17 +77,7 @@ function watchFiles(_a) {
|
||||
const lastUpdatedFilePath = typeof lastUpdatedFile == "string"
|
||||
? lastUpdatedFile
|
||||
: lastUpdatedFile.path;
|
||||
global.SYNCING = true;
|
||||
yield (0, sync_1.default)({
|
||||
dirPath: lastUpdatedFilePath,
|
||||
dirs: files,
|
||||
options,
|
||||
isFiles: true,
|
||||
firstRun: true,
|
||||
});
|
||||
setTimeout(() => {
|
||||
global.SYNCING = false;
|
||||
}, UPDATE_TIMEOUT);
|
||||
scheduler.enqueue(lastUpdatedFilePath, true);
|
||||
}
|
||||
catch (error) {
|
||||
console.log("ERROR:", error.message);
|
||||
|
||||
Reference in New Issue
Block a user