Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@matrixai/async-locks

Package Overview
Dependencies
Maintainers
3
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@matrixai/async-locks - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

jest.config.mjs

4

dist/Barrier.d.ts
import type { ResourceRelease } from '@matrixai/resources';
import type { ContextTimedInput } from './types';
import type { ContextTimedInput } from './types.js';
import { PromiseCancellable } from '@matrixai/async-cancellable';
import Lock from './Lock';
import Lock from './Lock.js';
declare class Barrier {

@@ -6,0 +6,0 @@ protected lock: Lock;

@@ -1,8 +0,3 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const async_cancellable_1 = require("@matrixai/async-cancellable");
const Lock_1 = __importDefault(require("./Lock"));
import { PromiseCancellable } from '@matrixai/async-cancellable';
import Lock from './Lock.js';
class Barrier {

@@ -13,3 +8,3 @@ lock;

static async createBarrier(count) {
const lock = new Lock_1.default();
const lock = new Lock();
const [release] = await lock.lock()();

@@ -34,7 +29,7 @@ return new this(count, lock, release);

if (!this.lock.isLocked()) {
return async_cancellable_1.PromiseCancellable.resolve();
return PromiseCancellable.resolve();
}
this._count = Math.max(this._count - 1, 0);
if (this._count === 0) {
return async_cancellable_1.PromiseCancellable.from(this.release());
return PromiseCancellable.from(this.release());
}

@@ -46,3 +41,3 @@ else {

}
exports.default = Barrier;
export default Barrier;
//# sourceMappingURL=Barrier.js.map

@@ -1,17 +0,11 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorAsyncLocksMonitorDeadlock = exports.ErrorAsyncLocksMonitorLockType = exports.ErrorAsyncLocksLockBoxConflict = exports.ErrorAsyncLocksTimeout = exports.ErrorAsyncLocks = void 0;
const errors_1 = require("@matrixai/errors");
class ErrorAsyncLocks extends errors_1.AbstractError {
import { AbstractError } from '@matrixai/errors';
class ErrorAsyncLocks extends AbstractError {
static description = 'Async locks error';
}
exports.ErrorAsyncLocks = ErrorAsyncLocks;
class ErrorAsyncLocksTimeout extends ErrorAsyncLocks {
static description = 'Async locks timeout';
}
exports.ErrorAsyncLocksTimeout = ErrorAsyncLocksTimeout;
class ErrorAsyncLocksLockBoxConflict extends ErrorAsyncLocks {
static description = 'LockBox cannot lock same ID with different Lockable classes';
}
exports.ErrorAsyncLocksLockBoxConflict = ErrorAsyncLocksLockBoxConflict;
/**

@@ -27,7 +21,6 @@ * If you get this exception, this means within the same `Monitor` instance,

}
exports.ErrorAsyncLocksMonitorLockType = ErrorAsyncLocksMonitorLockType;
class ErrorAsyncLocksMonitorDeadlock extends ErrorAsyncLocks {
static description = 'Monitor has met a potential deadlock';
}
exports.ErrorAsyncLocksMonitorDeadlock = ErrorAsyncLocksMonitorDeadlock;
export { ErrorAsyncLocks, ErrorAsyncLocksTimeout, ErrorAsyncLocksLockBoxConflict, ErrorAsyncLocksMonitorLockType, ErrorAsyncLocksMonitorDeadlock, };
//# sourceMappingURL=errors.js.map

@@ -1,10 +0,10 @@

export { default as Lock } from './Lock';
export { default as RWLockReader } from './RWLockReader';
export { default as RWLockWriter } from './RWLockWriter';
export { default as LockBox } from './LockBox';
export { default as Barrier } from './Barrier';
export { default as Semaphore } from './Semaphore';
export { default as Monitor } from './Monitor';
export * as utils from './utils';
export * as errors from './errors';
export * from './types';
export { default as Lock } from './Lock.js';
export { default as RWLockReader } from './RWLockReader.js';
export { default as RWLockWriter } from './RWLockWriter.js';
export { default as LockBox } from './LockBox.js';
export { default as Barrier } from './Barrier.js';
export { default as Semaphore } from './Semaphore.js';
export { default as Monitor } from './Monitor.js';
export * as utils from './utils.js';
export * as errors from './errors.js';
export * from './types.js';

@@ -1,50 +0,11 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.errors = exports.utils = exports.Monitor = exports.Semaphore = exports.Barrier = exports.LockBox = exports.RWLockWriter = exports.RWLockReader = exports.Lock = void 0;
var Lock_1 = require("./Lock");
Object.defineProperty(exports, "Lock", { enumerable: true, get: function () { return __importDefault(Lock_1).default; } });
var RWLockReader_1 = require("./RWLockReader");
Object.defineProperty(exports, "RWLockReader", { enumerable: true, get: function () { return __importDefault(RWLockReader_1).default; } });
var RWLockWriter_1 = require("./RWLockWriter");
Object.defineProperty(exports, "RWLockWriter", { enumerable: true, get: function () { return __importDefault(RWLockWriter_1).default; } });
var LockBox_1 = require("./LockBox");
Object.defineProperty(exports, "LockBox", { enumerable: true, get: function () { return __importDefault(LockBox_1).default; } });
var Barrier_1 = require("./Barrier");
Object.defineProperty(exports, "Barrier", { enumerable: true, get: function () { return __importDefault(Barrier_1).default; } });
var Semaphore_1 = require("./Semaphore");
Object.defineProperty(exports, "Semaphore", { enumerable: true, get: function () { return __importDefault(Semaphore_1).default; } });
var Monitor_1 = require("./Monitor");
Object.defineProperty(exports, "Monitor", { enumerable: true, get: function () { return __importDefault(Monitor_1).default; } });
exports.utils = __importStar(require("./utils"));
exports.errors = __importStar(require("./errors"));
__exportStar(require("./types"), exports);
export { default as Lock } from './Lock.js';
export { default as RWLockReader } from './RWLockReader.js';
export { default as RWLockWriter } from './RWLockWriter.js';
export { default as LockBox } from './LockBox.js';
export { default as Barrier } from './Barrier.js';
export { default as Semaphore } from './Semaphore.js';
export { default as Monitor } from './Monitor.js';
export * as utils from './utils.js';
export * as errors from './errors.js';
export * from './types.js';
//# sourceMappingURL=index.js.map
import type { PromiseCancellable } from '@matrixai/async-cancellable';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types';
import Semaphore from './Semaphore';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types.js';
import Semaphore from './Semaphore.js';
declare class Lock implements Lockable {

@@ -5,0 +5,0 @@ protected semaphore: Semaphore;

@@ -1,10 +0,5 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const resources_1 = require("@matrixai/resources");
const Semaphore_1 = __importDefault(require("./Semaphore"));
import { withF, withG } from '@matrixai/resources';
import Semaphore from './Semaphore.js';
class Lock {
semaphore = new Semaphore_1.default(1);
semaphore = new Semaphore(1);
get count() {

@@ -33,10 +28,10 @@ return this.semaphore.count;

const f = params.pop();
return (0, resources_1.withF)([this.lock(...params)], ([lock]) => f(lock));
return withF([this.lock(...params)], ([lock]) => f(lock));
}
withG(...params) {
const g = params.pop();
return (0, resources_1.withG)([this.lock(...params)], ([lock]) => g(lock));
return withG([this.lock(...params)], ([lock]) => g(lock));
}
}
exports.default = Lock;
export default Lock;
//# sourceMappingURL=Lock.js.map

@@ -1,2 +0,2 @@

import type { ResourceAcquireCancellable, Lockable, LockRequest, LockAcquireCancellable, LockAcquired, ContextTimedInput } from './types';
import type { ResourceAcquireCancellable, Lockable, LockRequest, LockAcquireCancellable, LockAcquired, ContextTimedInput } from './types.js';
import { PromiseCancellable } from '@matrixai/async-cancellable';

@@ -3,0 +3,0 @@ declare class LockBox<L extends Lockable = Lockable> implements Lockable {

@@ -1,30 +0,5 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const async_cancellable_1 = require("@matrixai/async-cancellable");
const resources_1 = require("@matrixai/resources");
const utils = __importStar(require("./utils"));
const errors = __importStar(require("./errors"));
import { PromiseCancellable } from '@matrixai/async-cancellable';
import { withF, withG } from '@matrixai/resources';
import * as utils from './utils.js';
import * as errors from './errors.js';
class LockBox {

@@ -192,3 +167,3 @@ _locks = new Map();

};
return async_cancellable_1.PromiseCancellable.from(f(), (signal) => {
return PromiseCancellable.from(f(), (signal) => {
signal.addEventListener('abort', () => {

@@ -220,3 +195,3 @@ currentP.cancel(signal.reason);

const waitP = Promise.all(waitPs).then(() => { });
return async_cancellable_1.PromiseCancellable.from(waitP, (signal) => {
return PromiseCancellable.from(waitP, (signal) => {
signal.addEventListener('abort', () => {

@@ -233,3 +208,3 @@ waitPs.reverse();

if (lock == null)
return async_cancellable_1.PromiseCancellable.resolve();
return PromiseCancellable.resolve();
return lock.waitForUnlock(ctx);

@@ -240,3 +215,3 @@ }

const f = params.pop();
return (0, resources_1.withF)([this.lock(...params)], ([lockBox]) => f(lockBox));
return withF([this.lock(...params)], ([lockBox]) => f(lockBox));
}

@@ -247,7 +222,7 @@ withMultiF(...params) {

const lockAcquires_ = lockAcquires.map(([key, lockAcquire, ...lockingParams]) => (...r) => lockAcquire(...r).then(([lockRelease, lock]) => [lockRelease, [key, lock, ...lockingParams]]));
return (0, resources_1.withF)(lockAcquires_, f);
return withF(lockAcquires_, f);
}
withG(...params) {
const g = params.pop();
return (0, resources_1.withG)([this.lock(...params)], ([lockBox]) => g(lockBox));
return withG([this.lock(...params)], ([lockBox]) => g(lockBox));
}

@@ -258,6 +233,6 @@ withMultiG(...params) {

const lockAcquires_ = lockAcquires.map(([key, lockAcquire, ...lockingParams]) => (...r) => lockAcquire(...r).then(([lockRelease, lock]) => [lockRelease, [key, lock, ...lockingParams]]));
return (0, resources_1.withG)(lockAcquires_, g);
return withG(lockAcquires_, g);
}
}
exports.default = LockBox;
export default LockBox;
//# sourceMappingURL=LockBox.js.map
import type { ResourceRelease } from '@matrixai/resources';
import type RWLockWriter from './RWLockWriter';
import type RWLockReader from './RWLockReader';
import type LockBox from './LockBox';
import type { ResourceAcquireCancellable, Lockable, RWLockRequest, ContextTimedInput } from './types';
import type RWLockWriter from './RWLockWriter.js';
import type RWLockReader from './RWLockReader.js';
import type LockBox from './LockBox.js';
import type { ResourceAcquireCancellable, Lockable, RWLockRequest, ContextTimedInput } from './types.js';
import { PromiseCancellable } from '@matrixai/async-cancellable';

@@ -7,0 +7,0 @@ declare class Monitor<RWLock extends RWLockReader | RWLockWriter> implements Lockable {

@@ -1,29 +0,4 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const async_cancellable_1 = require("@matrixai/async-cancellable");
const resources_1 = require("@matrixai/resources");
const errors = __importStar(require("./errors"));
import { PromiseCancellable } from '@matrixai/async-cancellable';
import { withF, withG } from '@matrixai/resources';
import * as errors from './errors.js';
class Monitor {

@@ -216,3 +191,3 @@ /**

};
return async_cancellable_1.PromiseCancellable.from(f(), (signal) => {
return PromiseCancellable.from(f(), (signal) => {
signal.addEventListener('abort', () => {

@@ -273,3 +248,3 @@ currentP?.cancel(signal.reason);

const waitP = Promise.all(waitPs).then(() => { });
return async_cancellable_1.PromiseCancellable.from(waitP, (signal) => {
return PromiseCancellable.from(waitP, (signal) => {
signal.addEventListener('abort', () => {

@@ -286,3 +261,3 @@ waitPs.reverse();

if (lock === undefined)
return async_cancellable_1.PromiseCancellable.resolve();
return PromiseCancellable.resolve();
if (lock.status === 'acquiring') {

@@ -298,7 +273,7 @@ return this.lockBox.locks.get(key).waitForUnlock(ctx);

const f = params.pop();
return (0, resources_1.withF)([this.lock(...params)], ([monitor]) => f(monitor));
return withF([this.lock(...params)], ([monitor]) => f(monitor));
}
withG(...params) {
const g = params.pop();
return (0, resources_1.withG)([this.lock(...params)], ([monitor]) => g(monitor));
return withG([this.lock(...params)], ([monitor]) => g(monitor));
}

@@ -352,3 +327,3 @@ setPendingLock(key, lockType) {

}
exports.default = Monitor;
export default Monitor;
//# sourceMappingURL=Monitor.js.map
import type { ResourceRelease } from '@matrixai/resources';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types.js';
import { PromiseCancellable } from '@matrixai/async-cancellable';
import Lock from './Lock';
import Lock from './Lock.js';
/**

@@ -6,0 +6,0 @@ * Read-preferring read write lock

@@ -1,34 +0,6 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const async_cancellable_1 = require("@matrixai/async-cancellable");
const resources_1 = require("@matrixai/resources");
const Lock_1 = __importDefault(require("./Lock"));
const utils = __importStar(require("./utils"));
const errors = __importStar(require("./errors"));
import { PromiseCancellable } from '@matrixai/async-cancellable';
import { withF, withG } from '@matrixai/resources';
import Lock from './Lock.js';
import * as utils from './utils.js';
import * as errors from './errors.js';
/**

@@ -38,4 +10,4 @@ * Read-preferring read write lock

class RWLockReader {
readersLock = new Lock_1.default();
writersLock = new Lock_1.default();
readersLock = new Lock();
writersLock = new Lock();
writersRelease;

@@ -174,3 +146,3 @@ readerCountBlocked = 0;

const waitWritersLockP = this.writersLock.waitForUnlock(ctx);
return async_cancellable_1.PromiseCancellable.all([waitReadersLockP, waitWritersLockP]).then(() => { }, undefined, (signal) => {
return PromiseCancellable.all([waitReadersLockP, waitWritersLockP]).then(() => { }, undefined, (signal) => {
signal.addEventListener('abort', () => {

@@ -205,7 +177,7 @@ waitReadersLockP.cancel(signal.reason);

const f = params.pop();
return (0, resources_1.withF)([this.read(...params)], ([lock]) => f(lock));
return withF([this.read(...params)], ([lock]) => f(lock));
}
withWriteF(...params) {
const f = params.pop();
return (0, resources_1.withF)([this.write(...params)], ([lock]) => f(lock));
return withF([this.write(...params)], ([lock]) => f(lock));
}

@@ -235,10 +207,10 @@ withG(...params) {

const g = params.pop();
return (0, resources_1.withG)([this.read(...params)], ([lock]) => g(lock));
return withG([this.read(...params)], ([lock]) => g(lock));
}
withWriteG(...params) {
const g = params.pop();
return (0, resources_1.withG)([this.write(...params)], ([lock]) => g(lock));
return withG([this.write(...params)], ([lock]) => g(lock));
}
}
exports.default = RWLockReader;
export default RWLockReader;
//# sourceMappingURL=RWLockReader.js.map
import type { ResourceRelease } from '@matrixai/resources';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types.js';
import { PromiseCancellable } from '@matrixai/async-cancellable';
import Lock from './Lock';
import Lock from './Lock.js';
/**

@@ -6,0 +6,0 @@ * Write-preferring read write lock

@@ -1,34 +0,6 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const resources_1 = require("@matrixai/resources");
const async_cancellable_1 = require("@matrixai/async-cancellable");
const Lock_1 = __importDefault(require("./Lock"));
const utils = __importStar(require("./utils"));
const errors = __importStar(require("./errors"));
import { withF, withG } from '@matrixai/resources';
import { PromiseCancellable } from '@matrixai/async-cancellable';
import Lock from './Lock.js';
import * as utils from './utils.js';
import * as errors from './errors.js';
/**

@@ -38,4 +10,4 @@ * Write-preferring read write lock

class RWLockWriter {
readersLock = new Lock_1.default();
writersLock = new Lock_1.default();
readersLock = new Lock();
writersLock = new Lock();
readersRelease;

@@ -181,3 +153,3 @@ readerCountBlocked = 0;

const waitWritersLockP = this.writersLock.waitForUnlock(ctx);
return async_cancellable_1.PromiseCancellable.all([waitReadersLockP, waitWritersLockP]).then(() => { }, undefined, (signal) => {
return PromiseCancellable.all([waitReadersLockP, waitWritersLockP]).then(() => { }, undefined, (signal) => {
signal.addEventListener('abort', () => {

@@ -212,7 +184,7 @@ waitReadersLockP.cancel(signal.reason);

const f = params.pop();
return (0, resources_1.withF)([this.read(...params)], ([lock]) => f(lock));
return withF([this.read(...params)], ([lock]) => f(lock));
}
withWriteF(...params) {
const f = params.pop();
return (0, resources_1.withF)([this.write(...params)], ([lock]) => f(lock));
return withF([this.write(...params)], ([lock]) => f(lock));
}

@@ -242,10 +214,10 @@ withG(...params) {

const g = params.pop();
return (0, resources_1.withG)([this.read(...params)], ([lock]) => g(lock));
return withG([this.read(...params)], ([lock]) => g(lock));
}
withWriteG(...params) {
const g = params.pop();
return (0, resources_1.withG)([this.write(...params)], ([lock]) => g(lock));
return withG([this.write(...params)], ([lock]) => g(lock));
}
}
exports.default = RWLockWriter;
export default RWLockWriter;
//# sourceMappingURL=RWLockWriter.js.map
import type { PromiseCancellable } from '@matrixai/async-cancellable';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types';
import type { ResourceAcquireCancellable, Lockable, ContextTimedInput } from './types.js';
type Task = {

@@ -4,0 +4,0 @@ task: () => void;

@@ -1,29 +0,4 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const resources_1 = require("@matrixai/resources");
const utils = __importStar(require("./utils"));
const errors = __importStar(require("./errors"));
import { withF, withG } from '@matrixai/resources';
import * as utils from './utils.js';
import * as errors from './errors.js';
class Semaphore {

@@ -161,7 +136,7 @@ limit;

const f = params.pop();
return (0, resources_1.withF)([this.lock(...params)], ([semaphore]) => f(semaphore));
return withF([this.lock(...params)], ([semaphore]) => f(semaphore));
}
withG(...params) {
const g = params.pop();
return (0, resources_1.withG)([this.lock(...params)], ([semaphore]) => g(semaphore));
return withG([this.lock(...params)], ([semaphore]) => g(semaphore));
}

@@ -194,3 +169,3 @@ insertQueue(task) {

}
exports.default = Semaphore;
export default Semaphore;
//# sourceMappingURL=Semaphore.js.map

@@ -1,3 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
//# sourceMappingURL=types.js.map

@@ -1,2 +0,2 @@

import type { PromiseDeconstructed, ContextTimed, ContextTimedInput } from './types';
import type { PromiseDeconstructed, ContextTimed, ContextTimedInput } from './types.js';
import { PromiseCancellable } from '@matrixai/async-cancellable';

@@ -3,0 +3,0 @@ /**

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupTimedCancellable = exports.promise = void 0;
const async_cancellable_1 = require("@matrixai/async-cancellable");
const timer_1 = require("@matrixai/timer");
import { PromiseCancellable } from '@matrixai/async-cancellable';
import { Timer } from '@matrixai/timer';
/**

@@ -21,3 +18,2 @@ * Deconstructed promise

}
exports.promise = promise;
function setupTimedCancellable(f, lazy, delay, errorTimeoutConstructor, ctx, args) {

@@ -50,3 +46,3 @@ // There are 3 properties of timer and signal:

// Property A
const timer = new timer_1.Timer(() => void abortController.abort(e), ctx.timer ?? delay);
const timer = new Timer(() => void abortController.abort(e), ctx.timer ?? delay);
abortController.signal.addEventListener('abort', () => {

@@ -68,3 +64,3 @@ // Property B

// Property A
const timer = new timer_1.Timer(() => void abortController.abort(e), ctx.timer ?? delay);
const timer = new Timer(() => void abortController.abort(e), ctx.timer ?? delay);
const signalUpstream = ctx.signal;

@@ -94,3 +90,3 @@ const signalHandler = () => {

}
else if (ctx.timer instanceof timer_1.Timer && ctx.signal === undefined) {
else if (ctx.timer instanceof Timer && ctx.signal === undefined) {
abortController = new AbortController();

@@ -143,3 +139,3 @@ const e = new errorTimeoutConstructor();

// function's signal
return new async_cancellable_1.PromiseCancellable((resolve, reject, signal) => {
return new PromiseCancellable((resolve, reject, signal) => {
if (!lazy) {

@@ -160,3 +156,3 @@ if (signal.aborted) {

}
exports.setupTimedCancellable = setupTimedCancellable;
export { promise, setupTimedCancellable };
//# sourceMappingURL=utils.js.map
{
"name": "@matrixai/async-locks",
"version": "4.0.0",
"version": "5.0.0",
"author": "Roger Qiu",

@@ -11,4 +11,18 @@ "description": "Asynchronous locking utilities",

},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./*.js": {
"types": "./dist/*.d.ts",
"import": "./dist/*.js"
},
"./*": "./dist/*"
},
"imports": {
"#*": "./dist/*"
},
"scripts": {

@@ -18,6 +32,6 @@ "prepare": "tsc -p ./tsconfig.build.json",

"postversion": "npm install --package-lock-only --ignore-scripts --silent",
"ts-node": "ts-node",
"test": "jest",
"lint": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}'",
"lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}' --fix",
"tsx": "tsx",
"test": "node ./scripts/test.mjs",
"lint": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}'",
"lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}' --fix",
"lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +",

@@ -27,29 +41,27 @@ "docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src"

"dependencies": {
"@matrixai/async-cancellable": "^1.1.1",
"@matrixai/errors": "^1.1.7",
"@matrixai/resources": "^1.1.5",
"@matrixai/timer": "^1.1.1"
"@matrixai/async-cancellable": "^2.0.0",
"@matrixai/errors": "^2.0.1",
"@matrixai/resources": "^2.0.0",
"@matrixai/timer": "^2.0.0"
},
"devDependencies": {
"@swc/core": "^1.3.62",
"@swc/jest": "^0.2.26",
"@types/jest": "^28.1.3",
"@swc/core": "^1.3.76",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.5.2",
"@types/node": "^18.15.0",
"@typescript-eslint/eslint-plugin": "^5.45.1",
"@typescript-eslint/parser": "^5.45.1",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.1",
"jest-extended": "^3.0.1",
"jest-junit": "^14.0.0",
"prettier": "^2.6.2",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^5.0.0-alpha.2",
"jest": "^29.6.2",
"jest-extended": "^4.0.0",
"jest-junit": "^16.0.0",
"prettier": "^3.0.0",
"shx": "^0.3.4",
"ts-jest": "^28.0.5",
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.9.0",
"typedoc": "^0.23.21",
"typescript": "^4.9.3"
"tsx": "^3.12.7",
"typedoc": "^0.24.8",
"typescript": "^5.1.6"
}
}

@@ -8,2 +8,14 @@ # js-async-locks

JavaScript exposes the ability to create interleaved execution of asynchronous
operations. When this is done with shared state between asynchronous
overlapping functions that perform partial state transitions, this can lead to
race conditions or data corruption and clobbering, or just invalid pre-condition
or post-condition behaviour.
This library provides multiple synchronization constructs that allow one to
precisely control concurrent operations. These constructs are intended for
pessimistic concurrency control. If you can prefer to use optimistic concurrency
control mechanisms. But that is outside the scope of this library. In many cases
you cannot use optimistic methods, and thus you need this library.
## Installation

@@ -25,3 +37,3 @@

# run the repl (this allows you to import from ./src)
npm run ts-node
npm run tsx
# run the tests

@@ -28,0 +40,0 @@ npm run test

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc