aboutsummaryrefslogtreecommitdiff
path: root/common/lock.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/lock.js')
-rw-r--r--common/lock.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/common/lock.js b/common/lock.js
index 8dd2f5b..f577481 100644
--- a/common/lock.js
+++ b/common/lock.js
@@ -68,9 +68,20 @@ function _lock(lock, cb) {
#EXPORT lock => new Promise(resolve => _lock(lock, resolve)) AS lock
+function try_lock(lock)
+{
+ if (lock.free) {
+ lock.free = false;
+ return true;
+ }
+
+ return false;
+}
+#EXPORT try_lock
+
function unlock(lock) {
if (lock.free)
- throw new Error("Attempting to release a free lock");
+ throw new Exception("Attempting to release a free lock");
if (lock.queue.length === 0) {
lock.free = true;