locker.js 1004 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * DevExtreme (core/utils/locker.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var errors = require("../errors");
  11. var Locker = function() {
  12. var info = {};
  13. var currentCount = function(lockName) {
  14. return info[lockName] || 0
  15. };
  16. return {
  17. obtain: function(lockName) {
  18. info[lockName] = currentCount(lockName) + 1
  19. },
  20. release: function(lockName) {
  21. var count = currentCount(lockName);
  22. if (count < 1) {
  23. throw errors.Error("E0014")
  24. }
  25. if (1 === count) {
  26. delete info[lockName]
  27. } else {
  28. info[lockName] = count - 1
  29. }
  30. },
  31. locked: function(lockName) {
  32. return currentCount(lockName) > 0
  33. }
  34. }
  35. };
  36. module.exports = Locker;