Socket
Socket
Sign inDemoInstall

async-mutex

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-mutex - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

tslint.json

9

CHANGELOG.md

@@ -9,2 +9,9 @@ # Changelog

* Fix documentation for `acquire`
* Fix documentation for `acquire`
## 0.1.2
* Move to yarn
* Add tslint
* Switch tests to use ES6
* Add isLocked()

3

lib/index.js
"use strict";
var Mutex_1 = require('./Mutex');
Object.defineProperty(exports, "__esModule", { value: true });
var Mutex_1 = require("./Mutex");
exports.Mutex = Mutex_1.default;
import MutexInterface from './MutexInterface';
declare class Mutex implements MutexInterface {
isLocked(): boolean;
acquire(): Promise<MutexInterface.Releaser>;

@@ -4,0 +5,0 @@ runExclusive<T>(callback: MutexInterface.Worker<T>): Promise<T>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Mutex = (function () {

@@ -7,2 +8,5 @@ function Mutex() {

}
Mutex.prototype.isLocked = function () {
return this._pending;
};
Mutex.prototype.acquire = function () {

@@ -47,3 +51,2 @@ var _this = this;

}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Mutex;
interface MutexInterface {
acquire(): Promise<MutexInterface.Releaser>;
runExclusive<T>(callback: MutexInterface.Worker<T>): Promise<T>;
isLocked(): boolean;
}
declare module MutexInterface {
declare namespace MutexInterface {
interface Releaser {

@@ -7,0 +8,0 @@ (): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
{
"name": "async-mutex",
"version": "0.1.1",
"version": "0.1.2",
"description": "A mutex for guarding async workflows",
"scripts": {
"prepublish": "tsc",
"pretest": "typings install && tsc -p tsconfig.test.json",
"test": "mocha -R spec -u tdd test"
"prepublish": "tslint src/**/*.ts test/**/*.ts && tsc",
"pretest": "tslint src/**/*.ts test/**/*.ts && tsc -p tsconfig.test.json",
"test": "mocha -R spec -u tdd build/test"
},

@@ -21,8 +21,12 @@ "author": "Christian Speckner <cnspeckn@googlemail.com> (https://github.com/DirtyHairy/)",

"devDependencies": {
"mocha": "~3.1.0",
"typescript": "~2.0.3",
"typings": "~1.4.0"
"mocha": "~3.4.2",
"typescript": "~2.4.1"
},
"main": "lib/index.js",
"types": "lib/index.d.ts"
"types": "lib/index.d.ts",
"dependencies": {
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.5",
"tslint": "^5.4.3"
}
}

@@ -108,4 +108,10 @@ [![Build Status](https://travis-ci.org/DirtyHairy/async-mutex.svg?branch=master)](https://travis-ci.org/DirtyHairy/async-mutex)

### Checking whether the mutex is locked
ES5/ES6/Typescript
mutex.isLocked();
# License
Feel free to use this library under the conditions of the MIT license.
export {default as Mutex} from './Mutex';
export {default as MutexInterface} from './MutexInterface';
export {default as MutexInterface} from './MutexInterface';

@@ -5,4 +5,8 @@ import MutexInterface from './MutexInterface';

isLocked(): boolean {
return this._pending;
}
acquire(): Promise<MutexInterface.Releaser> {
const ticket = new Promise(resolve => this._queue.push(resolve));
const ticket = new Promise<MutexInterface.Releaser>(resolve => this._queue.push(resolve));

@@ -45,3 +49,3 @@ if (!this._pending) {

this._pending = true;
this._queue.shift()(this._dispatchNext.bind(this));
this._queue.shift()!(this._dispatchNext.bind(this));
} else {

@@ -48,0 +52,0 @@ this._pending = false;

@@ -7,5 +7,7 @@ interface MutexInterface {

isLocked(): boolean;
}
module MutexInterface {
namespace MutexInterface {

@@ -22,2 +24,2 @@ export interface Releaser {

export default MutexInterface;
export default MutexInterface;

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

/// <reference path="../typings/index.d.ts"/>
import * as assert from 'assert';

@@ -55,2 +53,3 @@

.runExclusive<number>(() => {
// tslint:disable-next-line:no-string-throw
throw 'foo';

@@ -91,2 +90,29 @@ })

});
test('new mutex is unlocked', function() {
assert(!mutex.isLocked());
});
test('isLocked reflects the mutex state', async function() {
const lock1 = mutex.acquire(),
lock2 = mutex.acquire();
assert(mutex.isLocked());
const releaser1 = await lock1;
assert(mutex.isLocked());
releaser1();
assert(mutex.isLocked());
const releaser2 = await lock2;
assert(mutex.isLocked());
releaser2();
assert(!mutex.isLocked());
});
});

@@ -6,7 +6,6 @@ {

"sourceMap": false,
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"declaration": true,
"outDir": "lib",
"lib": ["es5", "es6"]
"lib": ["es6"]
},

@@ -13,0 +12,0 @@ "include": ["src/**/*.ts"],

{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"target": "es6",
"strict": true,
"sourceMap": false,
"noImplicitAny": true,
"noImplicitThis": true,
"lib": ["es5", "es6", "dom"]
"outDir": "build"
},

@@ -10,0 +9,0 @@ "include": ["test/**/*.ts"],

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