UNPKG

rwlockfile

Version:

lockfile utility with reader/writers

29 lines (28 loc) 990 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class LockfileError extends Error { constructor({ msg, file, reason }) { super(msg || (reason ? `${reason}: ${file}` : `lock exists!: ${file}`)); this.code = 'ELOCK'; this.file = file; this.msg = msg; this.reason = reason; } } exports.LockfileError = LockfileError; class RWLockfileError extends LockfileError { constructor(status) { switch (status.status) { case 'write_lock': super({ file: status.file, msg: `write lock exists: ${status.job.reason || ''}` }); break; case 'read_lock': super({ file: status.file, msg: `read lock exists: ${status.jobs[0].reason || ''}` }); break; default: throw new Error(`Unexpected status: ${status.status}`); } this.status = status; } } exports.RWLockfileError = RWLockfileError;