Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Locks this item.
- * @param level Whether lock is share or exclusive.
- * @param isDeep Whether lock is deep.
- * @param requestedTimeOut Lock timeout which was requested by client.
- * Server may ignore this parameter and set any timeout.
- * @param owner Owner of the lock as specified by client.
- * @returns
- * Instance of @see LockResult with information about the lock.
- */
- public async lock(
- level: LockLevel | null,
- isDeep: boolean | null,
- requestedTimeOut: number | null,
- owner: string | null
- ): Promise<LockResult> {
- await this.requireUnlocked(level === LockLevel.shared);
- const token = randomBytes(16).toString('hex');
- // If timeout is absent or infinit timeout requested,
- // grant 5 minute lock.
- let timeOut = 5 * 60 * 1000;
- if (requestedTimeOut && (requestedTimeOut < 8640000000000000)) {
- timeOut = requestedTimeOut;
- }
- const lockInfo = new DateLockInfo();
- lockInfo.expiration = Date.now() + timeOut;
- lockInfo.isDeep = false;
- lockInfo.level = level !== null ? level : LockLevel.shared;
- lockInfo.lockRoot = this.path;
- lockInfo.lockToken = token;
- lockInfo.clientOwner = owner || '';
- lockInfo.timeOut = timeOut;
- this.saveLock(lockInfo);
- return new LockResult(lockInfo.lockToken, lockInfo.timeOut);
- }
Add Comment
Please, Sign In to add comment