1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 | var _tslib = require("tslib");
|
8 | var _react = require("react");
|
9 | function useLockFn(fn) {
|
10 | var _this = this;
|
11 | var lockRef = (0, _react.useRef)(false);
|
12 | return (0, _react.useCallback)(function () {
|
13 | var args = [];
|
14 | for (var _i = 0; _i < arguments.length; _i++) {
|
15 | args[_i] = arguments[_i];
|
16 | }
|
17 | return (0, _tslib.__awaiter)(_this, void 0, void 0, function () {
|
18 | var ret, e_1;
|
19 | return (0, _tslib.__generator)(this, function (_a) {
|
20 | switch (_a.label) {
|
21 | case 0:
|
22 | if (lockRef.current) return [2 ];
|
23 | lockRef.current = true;
|
24 | _a.label = 1;
|
25 | case 1:
|
26 | _a.trys.push([1, 3,, 4]);
|
27 | return [4 , fn.apply(void 0, (0, _tslib.__spreadArray)([], (0, _tslib.__read)(args), false))];
|
28 | case 2:
|
29 | ret = _a.sent();
|
30 | lockRef.current = false;
|
31 | return [2 , ret];
|
32 | case 3:
|
33 | e_1 = _a.sent();
|
34 | lockRef.current = false;
|
35 | throw e_1;
|
36 | case 4:
|
37 | return [2 ];
|
38 | }
|
39 | });
|
40 | });
|
41 | }, [fn]);
|
42 | }
|
43 | var _default = useLockFn;
|
44 | exports["default"] = _default; |
\ | No newline at end of file |