diff options
author | Wojtek Kosior <koszko@koszko.org> | 2021-06-30 12:28:05 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2021-06-30 12:28:05 +0200 |
commit | 261548ff184926567a623e90df7954aeef842d59 (patch) | |
tree | 9b5697a77c758eaae969a8fba8b4edea5ecf59d4 /common/lock.js | |
parent | 83a8d263f6efddf4f742bf7a687d10bfd1907ef8 (diff) | |
download | browser-extension-261548ff184926567a623e90df7954aeef842d59.tar.gz browser-extension-261548ff184926567a623e90df7954aeef842d59.zip |
emply an sh-based build system; make some changes to blocking
Diffstat (limited to 'common/lock.js')
-rw-r--r-- | common/lock.js | 68 |
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 + */ |