UNPKG

literate-elm

Version:

Runs literate Elm code blocks and calculates Elm expressions

60 lines 2.91 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.unlock = exports.lock = exports.ensureUnlocked = exports.isLocked = exports.hasBeenTouchedWithin = exports.getLastTouchedAt = exports.touch = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const sleep_promise_1 = __importDefault(require("sleep-promise")); const checkInterval = 100; const defaultLockTimeout = 5000; const touch = (path) => __awaiter(void 0, void 0, void 0, function* () { yield fs_extra_1.default.writeFile(`${path}.touchfile`, ""); }); exports.touch = touch; const getLastTouchedAt = (path) => __awaiter(void 0, void 0, void 0, function* () { try { return (yield fs_extra_1.default.stat(`${path}.touchfile`)).mtimeMs; } catch (e) { return 0; } }); exports.getLastTouchedAt = getLastTouchedAt; const hasBeenTouchedWithin = (path, intervalInMs) => __awaiter(void 0, void 0, void 0, function* () { return +new Date() - (yield (0, exports.getLastTouchedAt)(path)) < intervalInMs; }); exports.hasBeenTouchedWithin = hasBeenTouchedWithin; const isLocked = (path) => __awaiter(void 0, void 0, void 0, function* () { return !!(yield fs_extra_1.default.pathExists(`${path}.lockfile`)); }); exports.isLocked = isLocked; const ensureUnlocked = (path, timeout = defaultLockTimeout) => __awaiter(void 0, void 0, void 0, function* () { const timeToGiveUp = +new Date() + timeout; do { if (!(yield (0, exports.isLocked)(path))) { return; } (0, sleep_promise_1.default)(checkInterval); } while (+new Date() < timeToGiveUp); throw new Error("Unlock failed"); }); exports.ensureUnlocked = ensureUnlocked; const lock = (path, identifier) => __awaiter(void 0, void 0, void 0, function* () { yield fs_extra_1.default.writeFile(`${path}.lockfile`, identifier || ""); }); exports.lock = lock; const unlock = (path) => __awaiter(void 0, void 0, void 0, function* () { yield fs_extra_1.default.remove(`${path}.lockfile`); }); exports.unlock = unlock; //# sourceMappingURL=auxFiles.js.map