UNPKG

@liqd-js/mongodb-model

Version:
18 lines (17 loc) 684 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Log = void 0; const promises_1 = require("fs/promises"); class Log { static queues = new Map(); static append(path, log) { const previousPromise = this.queues.get(path) || Promise.resolve(); const newPromise = previousPromise.then(() => (0, promises_1.appendFile)(path, log)).catch((err) => { console.error(`Error appending log for id ${path}:`, err); }); this.queues.set(path, newPromise); newPromise.finally(() => (this.queues.get(path) === newPromise) && this.queues.delete(path)); return newPromise; } } exports.Log = Log;