No Description

block.js 778B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. const container = new Map();
  6. const callbacks = new Map();
  7. exports.default = {
  8. lock: id => {
  9. let count = container.get(id) || 0;
  10. container.set(id, ++count);
  11. },
  12. release: function (id) {
  13. let count = container.get(id) || 0;
  14. if (count) {
  15. container.set(id, --count);
  16. }
  17. this.check();
  18. },
  19. check: () => {
  20. for (let [id, callback] of callbacks) {
  21. const count = container.get(id);
  22. if (count === 0) {
  23. container.delete(id);
  24. callback();
  25. }
  26. }
  27. },
  28. wait: function (id, callback) {
  29. callbacks.set(id, function () {
  30. callbacks.delete(id);
  31. callback();
  32. });
  33. this.check();
  34. }
  35. };
  36. module.exports = exports["default"];