async-mutex
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -90,4 +90,7 @@ import { __awaiter, __generator } from "tslib"; | ||
return new Promise(function (resolve, reject) { | ||
sync.waitForUnlock(weight).then(resolve); | ||
setTimeout(function () { return reject(timeoutError); }, timeout); | ||
var handle = setTimeout(function () { return reject(timeoutError); }, timeout); | ||
sync.waitForUnlock(weight).then(function () { | ||
clearTimeout(handle); | ||
resolve(); | ||
}); | ||
}); | ||
@@ -94,0 +97,0 @@ }, |
@@ -93,4 +93,7 @@ "use strict"; | ||
return new Promise(function (resolve, reject) { | ||
sync.waitForUnlock(weight).then(resolve); | ||
setTimeout(function () { return reject(timeoutError); }, timeout); | ||
var handle = setTimeout(function () { return reject(timeoutError); }, timeout); | ||
sync.waitForUnlock(weight).then(function () { | ||
clearTimeout(handle); | ||
resolve(); | ||
}); | ||
}); | ||
@@ -97,0 +100,0 @@ }, |
{ | ||
"name": "async-mutex", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A mutex for guarding async workflows", | ||
@@ -57,8 +57,8 @@ "scripts": { | ||
"devDependencies": { | ||
"@sinonjs/fake-timers": "^9.1.2", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^18.7.14", | ||
"@sinonjs/fake-timers": "^11.2.2", | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.11.5", | ||
"@types/sinonjs__fake-timers": "^8.1.2", | ||
"@typescript-eslint/eslint-plugin": "^5.36.1", | ||
"@typescript-eslint/parser": "^5.36.1", | ||
"@typescript-eslint/eslint-plugin": "^6.19.0", | ||
"@typescript-eslint/parser": "^6.19.0", | ||
"coveralls": "^3.1.1", | ||
@@ -69,7 +69,7 @@ "eslint": "^8.23.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.7.1", | ||
"prettier": "^3.2.4", | ||
"prettier-plugin-import-sort": "^0.0.7", | ||
"rollup": "^2.56.3", | ||
"rollup": "^4.9.5", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.8.2" | ||
"typescript": "^5.3.3" | ||
}, | ||
@@ -76,0 +76,0 @@ "main": "lib/index.js", |
@@ -32,3 +32,3 @@ [![Build status](https://github.com/DirtyHairy/async-mutex/workflows/Build%20and%20Tests/badge.svg)](https://github.com/DirtyHairy/async-mutex/actions?query=workflow%3A%22Build+and+Tests%22) | ||
available. Once the async process is complete (usually taking multiple | ||
spins of the event loop), a callback supplied to the caller is called in order | ||
spins of the event loop), a callback supplied to the caller should be called in order | ||
to release the mutex, allowing the next scheduled worker to execute. | ||
@@ -43,3 +43,3 @@ | ||
A semaphore is a data structure that is initialized to an arbitrary integer value and that | ||
A semaphore is a data structure that is initialized with an arbitrary integer value and that | ||
can be locked multiple times. | ||
@@ -112,6 +112,6 @@ As long as the semaphore value is positive, locking it will return the current value | ||
mutex | ||
.runExclusive(function() { | ||
.runExclusive(() => { | ||
// ... | ||
}) | ||
.then(function(result) { | ||
.then((result) => { | ||
// ... | ||
@@ -134,3 +134,3 @@ }); | ||
The mutex is released and the result rejected if an exception occurs during execution | ||
if the callback. | ||
of the callback. | ||
@@ -184,3 +184,3 @@ ### Manual locking / releasing | ||
### Cancelling pending locks. | ||
### Cancelling pending locks | ||
@@ -241,3 +241,3 @@ Pending locks can be cancelled by calling `cancel()` on the mutex. This will reject | ||
will not lock the mutex, and there is no guarantee that the mutex will still be available | ||
once a async barrier has been encountered. | ||
once an async barrier has been encountered. | ||
@@ -339,11 +339,11 @@ Promise style: | ||
semaphore by the specified value, and the semaphore will only be acquired once the its | ||
value is greater or equal to. | ||
value is greater or equal to `weight`. | ||
### Unscoped release | ||
As an alternative to calling the `release` callback return by `acquire`, the mutex | ||
As an alternative to calling the `release` callback returned by `acquire`, the semaphore | ||
can be released by calling `release` directly on it: | ||
```typescript | ||
mutex.release(); | ||
semaphore.release(); | ||
``` | ||
@@ -370,3 +370,3 @@ | ||
The semaphore is considered to be locked if its value is either zero or negative; | ||
The semaphore is considered to be locked if its value is either zero or negative. | ||
@@ -382,3 +382,3 @@ ### Setting the semaphore value | ||
### Cancelling pending locks. | ||
### Cancelling pending locks | ||
@@ -439,3 +439,3 @@ Pending locks can be cancelled by calling `cancel()` on the semaphore. This will reject | ||
will not lock the semaphore, and there is no guarantee that the semaphore will still be available | ||
once a async barrier has been encountered. | ||
once an async barrier has been encountered. | ||
@@ -458,3 +458,3 @@ Promise style: | ||
`waitForUnlock` accepts an optional argument `weight`. If `weight` is specified the promise | ||
will only resolve once the semaphore's value is greater or equal to weight; | ||
will only resolve once the semaphore's value is greater or equal to `weight`; | ||
@@ -513,3 +513,2 @@ ## Limiting the time waiting for a mutex or semaphore to become available | ||
}); | ||
``` | ||
@@ -530,3 +529,2 @@ | ||
} | ||
``` | ||
@@ -537,4 +535,10 @@ | ||
```typescript | ||
tryAcquire(semaphoreOrMutex, new Error('new fancy error')) | ||
.runExclusive(() => { | ||
// ... | ||
}); | ||
``` | ||
# License | ||
Feel free to use this library under the conditions of the MIT license. |
Sorry, the diff of this file is not supported yet
54722
877
531