aboutsummaryrefslogtreecommitdiff
path: root/common/lock.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/lock.js')
-rw-r--r--common/lock.js68
1 files changed, 34 insertions, 34 deletions
diff --git a/common/lock.js b/common/lock.js
index 3358393..1130762 100644
--- a/common/lock.js
+++ b/common/lock.js
@@ -19,40 +19,40 @@
* in a promise.
*/
-"use strict";
-
-(() => {
- function make_lock() {
- return {free: true, queue: []};
+function make_lock() {
+ return {free: true, queue: []};
+}
+
+function _lock(lock, cb) {
+ if (lock.free) {
+ lock.free = false;
+ setTimeout(cb);
+ } else {
+ lock.queue.push(cb);
}
-
- function _lock(lock, cb) {
- if (lock.free) {
- lock.free = false;
- setTimeout(cb);
- } else {
- lock.queue.push(cb);
- }
+}
+
+function lock(lock) {
+ return new Promise((resolve, reject) => _lock(lock, resolve));
+}
+
+function unlock(lock) {
+ if (lock.free)
+ throw new Exception("Attempting to release a free lock");
+
+ if (lock.queue.length === 0) {
+ lock.free = true;
+ } else {
+ let cb = lock.queue[0];
+ lock.queue.splice(0, 1);
+ setTimeout(cb);
}
+}
- function lock(lock) {
- return new Promise((resolve, reject) => _lock(lock, resolve));
- }
-
- function unlock(lock) {
- if (lock.free)
- throw new Exception("Attempting to release a free lock");
-
- if (lock.queue.length === 0) {
- lock.free = true;
- } else {
- let cb = lock.queue[0];
- lock.queue.splice(0, 1);
- setTimeout(cb);
- }
- }
-
- window.make_lock = make_lock;
- window.lock = lock;
- window.unlock = unlock;
-})();
+/*
+ * EXPORTS_START
+ * EXPORT make_lock
+ * EXPORT lock
+ * EXPORT unlock
+ * EXPORTS_END
+ */