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.3 to 0.1.4

5

CHANGELOG.md

@@ -22,1 +22,6 @@ # Changelog

* Upgrade deps
## 0.1.4
* Documentation updates (thanks to hmil and 0xflotus)
* Update build dependencies

2

lib/Mutex.d.ts

@@ -6,3 +6,3 @@ import MutexInterface from './MutexInterface';

runExclusive<T>(callback: MutexInterface.Worker<T>): Promise<T>;
private _dispatchNext();
private _dispatchNext;
private _queue;

@@ -9,0 +9,0 @@ private _pending;

{
"name": "async-mutex",
"version": "0.1.3",
"version": "0.1.4",
"description": "A mutex for guarding async workflows",

@@ -20,8 +20,11 @@ "scripts": {

],
"files": [
"lib"
],
"devDependencies": {
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.5",
"mocha": "^3.4.2",
"tslint": "^5.4.3",
"typescript": "^2.4.1"
"@types/mocha": "^5.2.7",
"@types/node": "^12.7.8",
"mocha": "^6.2.0",
"tslint": "^5.20.0",
"typescript": "^3.6.3"
},

@@ -28,0 +31,0 @@ "main": "lib/index.js",

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

concurrent processes running on different threads. For example, before accessing
a non-threadsafe resource, a thread will lock the mutex. This is guranteed
a non-threadsafe resource, a thread will lock the mutex. This is guaranteed
to block the thread until no other thread holds a lock on the mutex and thus

@@ -41,7 +41,7 @@ enforces exclusive access to the resource. Once the operation is complete, the

The library is written in Typescript and will work in any environment that
The library is written in TypeScript and will work in any environment that
supports ES5 and ES6 promises. If ES6 promises are not supported natively,
a shim can be used (e.g. [core-js](https://github.com/zloirock/core-js)).
No external typings are required for using this library with
Typescript (version >= 2).
TypeScript (version >= 2).

@@ -51,13 +51,16 @@ ## Importing

ES5 / CommonJS
```javascript
var asyncMutex = require('async-mutex').Mutex;
```
var asyncMutex = require('async-mutex').Mutex;
ES6
```javascript
import {Mutex} from 'async-mutex';
```
import {Mutex} from 'async-mutex';
TypeScript
```typescript
import {Mutex, MutexInterface} from 'async-mutex';
```
Typescript
import {Mutex, MutexInterface} from 'async-mutex';
## API

@@ -67,6 +70,7 @@

ES5/ES6/Typescript
ES5/ES6/TypeScript
```typescript
const mutex = new Mutex();
```
const mutex = new Mutex();
Create a new mutex.

@@ -76,10 +80,11 @@

ES5/ES6/Typescript
ES5/ES6/TypeScript
```typescript
mutex
.acquire()
.then(function(release) {
// ...
});
```
mutex
.acquire()
.then(function(release) {
// ...
});
`acquire` returns an (ES6) promise that will resolve as soon as the mutex is

@@ -93,18 +98,43 @@ available and ready to be accessed. The promise resolves with a function `release` that

##### Async function example (ESnext/TypeScript)
```typescript
const release = await mutex.acquire();
try {
const i = await store.get();
await store.put(i + 1);
} finally {
release();
}
```
### Synchronized code execution
ES5/ES6/Typescript
ES5/ES6/TypeScript
```typescript
mutex
.runExclusive(function() {
// ...
})
.then(function(result) {
// ...
});
```
mutex
.runExclusive(function() {
// ...
})
.then(function(result) {
// ...
});
##### Async function example (ESnext/TypeScript)
This example is equivalent to the `async`/`await` example that
locks the mutex directly:
```typescript
await mutex.runExclusive(async () => {
const i = await store.get();
await store.put(i + 1);
});
```
`runExclusive` schedules the supplied callback to be run once the mutex is unlocked.
The function is expected to return a [Promises/A+](https://promisesaplus.com/)
compliant promise. Once the promise is resolved (or rejected), the mutex is released.
`runExclusive` returns a promise that adops the state of the function result.
`runExclusive` returns a promise that adopts the state of the function result.

@@ -116,8 +146,9 @@ The mutex is released and the result rejected if an exception occurs during execution

ES5/ES6/Typescript
ES5/ES6/TypeScript
```typescript
mutex.isLocked();
```
mutex.isLocked();
# License
Feel free to use this library under the conditions of the MIT license.
Feel free to use this library under the conditions of the MIT license.
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