rename promise-retry to retry
This commit is contained in:
10
src/locks.js
10
src/locks.js
@@ -2,7 +2,7 @@ import assert from 'node:assert';
|
||||
import BoxError from './boxerror.js';
|
||||
import database from './database.js';
|
||||
import logger from './logger.js';
|
||||
import promiseRetry from './promise-retry.js';
|
||||
import retry from './retry.js';
|
||||
|
||||
const { log } = logger('locks');
|
||||
|
||||
@@ -59,7 +59,7 @@ function canAcquire(data, type) {
|
||||
async function acquire(type) {
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
|
||||
await promiseRetry({ times: Number.MAX_SAFE_INTEGER, interval: 100, log, retry: (error) => error.reason === BoxError.CONFLICT }, async () => {
|
||||
await retry({ times: Number.MAX_SAFE_INTEGER, interval: 100, log, retry: (error) => error.reason === BoxError.CONFLICT }, async () => {
|
||||
const { version, data } = await read();
|
||||
const error = canAcquire(data, type);
|
||||
if (error) throw error;
|
||||
@@ -72,13 +72,13 @@ async function acquire(type) {
|
||||
async function wait(type) {
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
|
||||
await promiseRetry({ times: Number.MAX_SAFE_INTEGER, interval: 10000, log }, async () => await acquire(type));
|
||||
await retry({ times: Number.MAX_SAFE_INTEGER, interval: 10000, log }, async () => await acquire(type));
|
||||
}
|
||||
|
||||
async function release(type) {
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
|
||||
await promiseRetry({ times: Number.MAX_SAFE_INTEGER, interval: 100, log, retry: (error) => error.reason === BoxError.CONFLICT }, async () => {
|
||||
await retry({ times: Number.MAX_SAFE_INTEGER, interval: 100, log, retry: (error) => error.reason === BoxError.CONFLICT }, async () => {
|
||||
const { version, data } = await read();
|
||||
if (!(type in data)) throw new BoxError(BoxError.BAD_STATE, `Lock ${type} was never acquired`);
|
||||
if (data[type] !== gTaskId) throw new BoxError(BoxError.BAD_STATE, `Task ${gTaskId} attempted to release lock ${type} acquired by ${data[type]}`);
|
||||
@@ -98,7 +98,7 @@ async function releaseAll() {
|
||||
async function releaseByTaskId(taskId) {
|
||||
assert.strictEqual(typeof taskId, 'string');
|
||||
|
||||
await promiseRetry({ times: Number.MAX_SAFE_INTEGER, interval: 100, log, retry: (error) => error.reason === BoxError.CONFLICT }, async () => {
|
||||
await retry({ times: Number.MAX_SAFE_INTEGER, interval: 100, log, retry: (error) => error.reason === BoxError.CONFLICT }, async () => {
|
||||
const { version, data } = await read();
|
||||
|
||||
for (const type of Object.keys(data)) {
|
||||
|
||||
Reference in New Issue
Block a user