1234567891011121314151617181920212223242526272829303132333435363738 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- const container = new Map();
- const callbacks = new Map();
-
- exports.default = {
- lock: id => {
- let count = container.get(id) || 0;
- container.set(id, ++count);
- },
- release: function (id) {
- let count = container.get(id) || 0;
- if (count) {
- container.set(id, --count);
- }
- this.check();
- },
- check: () => {
- for (let [id, callback] of callbacks) {
- const count = container.get(id);
- if (count === 0) {
- container.delete(id);
- callback();
- }
- }
- },
- wait: function (id, callback) {
- callbacks.set(id, function () {
- callbacks.delete(id);
- callback();
- });
- this.check();
- }
- };
- module.exports = exports["default"];
|