没绑定过手机号的 允许会话十次,弹出验证码弹窗
This commit is contained in:
41
node_modules/async-mutex/es6/Mutex.js
generated
vendored
Normal file
41
node_modules/async-mutex/es6/Mutex.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
import Semaphore from './Semaphore';
|
||||
var Mutex = /** @class */ (function () {
|
||||
function Mutex(cancelError) {
|
||||
this._semaphore = new Semaphore(1, cancelError);
|
||||
}
|
||||
Mutex.prototype.acquire = function () {
|
||||
return __awaiter(this, arguments, void 0, function (priority) {
|
||||
var _a, releaser;
|
||||
if (priority === void 0) { priority = 0; }
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, this._semaphore.acquire(1, priority)];
|
||||
case 1:
|
||||
_a = _b.sent(), releaser = _a[1];
|
||||
return [2 /*return*/, releaser];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Mutex.prototype.runExclusive = function (callback, priority) {
|
||||
if (priority === void 0) { priority = 0; }
|
||||
return this._semaphore.runExclusive(function () { return callback(); }, 1, priority);
|
||||
};
|
||||
Mutex.prototype.isLocked = function () {
|
||||
return this._semaphore.isLocked();
|
||||
};
|
||||
Mutex.prototype.waitForUnlock = function (priority) {
|
||||
if (priority === void 0) { priority = 0; }
|
||||
return this._semaphore.waitForUnlock(1, priority);
|
||||
};
|
||||
Mutex.prototype.release = function () {
|
||||
if (this._semaphore.isLocked())
|
||||
this._semaphore.release();
|
||||
};
|
||||
Mutex.prototype.cancel = function () {
|
||||
return this._semaphore.cancel();
|
||||
};
|
||||
return Mutex;
|
||||
}());
|
||||
export default Mutex;
|
||||
1
node_modules/async-mutex/es6/MutexInterface.js
generated
vendored
Normal file
1
node_modules/async-mutex/es6/MutexInterface.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
153
node_modules/async-mutex/es6/Semaphore.js
generated
vendored
Normal file
153
node_modules/async-mutex/es6/Semaphore.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
import { E_CANCELED } from './errors';
|
||||
var Semaphore = /** @class */ (function () {
|
||||
function Semaphore(_value, _cancelError) {
|
||||
if (_cancelError === void 0) { _cancelError = E_CANCELED; }
|
||||
this._value = _value;
|
||||
this._cancelError = _cancelError;
|
||||
this._queue = [];
|
||||
this._weightedWaiters = [];
|
||||
}
|
||||
Semaphore.prototype.acquire = function (weight, priority) {
|
||||
var _this = this;
|
||||
if (weight === void 0) { weight = 1; }
|
||||
if (priority === void 0) { priority = 0; }
|
||||
if (weight <= 0)
|
||||
throw new Error("invalid weight ".concat(weight, ": must be positive"));
|
||||
return new Promise(function (resolve, reject) {
|
||||
var task = { resolve: resolve, reject: reject, weight: weight, priority: priority };
|
||||
var i = findIndexFromEnd(_this._queue, function (other) { return priority <= other.priority; });
|
||||
if (i === -1 && weight <= _this._value) {
|
||||
// Needs immediate dispatch, skip the queue
|
||||
_this._dispatchItem(task);
|
||||
}
|
||||
else {
|
||||
_this._queue.splice(i + 1, 0, task);
|
||||
}
|
||||
});
|
||||
};
|
||||
Semaphore.prototype.runExclusive = function (callback_1) {
|
||||
return __awaiter(this, arguments, void 0, function (callback, weight, priority) {
|
||||
var _a, value, release;
|
||||
if (weight === void 0) { weight = 1; }
|
||||
if (priority === void 0) { priority = 0; }
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, this.acquire(weight, priority)];
|
||||
case 1:
|
||||
_a = _b.sent(), value = _a[0], release = _a[1];
|
||||
_b.label = 2;
|
||||
case 2:
|
||||
_b.trys.push([2, , 4, 5]);
|
||||
return [4 /*yield*/, callback(value)];
|
||||
case 3: return [2 /*return*/, _b.sent()];
|
||||
case 4:
|
||||
release();
|
||||
return [7 /*endfinally*/];
|
||||
case 5: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Semaphore.prototype.waitForUnlock = function (weight, priority) {
|
||||
var _this = this;
|
||||
if (weight === void 0) { weight = 1; }
|
||||
if (priority === void 0) { priority = 0; }
|
||||
if (weight <= 0)
|
||||
throw new Error("invalid weight ".concat(weight, ": must be positive"));
|
||||
if (this._couldLockImmediately(weight, priority)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
else {
|
||||
return new Promise(function (resolve) {
|
||||
if (!_this._weightedWaiters[weight - 1])
|
||||
_this._weightedWaiters[weight - 1] = [];
|
||||
insertSorted(_this._weightedWaiters[weight - 1], { resolve: resolve, priority: priority });
|
||||
});
|
||||
}
|
||||
};
|
||||
Semaphore.prototype.isLocked = function () {
|
||||
return this._value <= 0;
|
||||
};
|
||||
Semaphore.prototype.getValue = function () {
|
||||
return this._value;
|
||||
};
|
||||
Semaphore.prototype.setValue = function (value) {
|
||||
this._value = value;
|
||||
this._dispatchQueue();
|
||||
};
|
||||
Semaphore.prototype.release = function (weight) {
|
||||
if (weight === void 0) { weight = 1; }
|
||||
if (weight <= 0)
|
||||
throw new Error("invalid weight ".concat(weight, ": must be positive"));
|
||||
this._value += weight;
|
||||
this._dispatchQueue();
|
||||
};
|
||||
Semaphore.prototype.cancel = function () {
|
||||
var _this = this;
|
||||
this._queue.forEach(function (entry) { return entry.reject(_this._cancelError); });
|
||||
this._queue = [];
|
||||
};
|
||||
Semaphore.prototype._dispatchQueue = function () {
|
||||
this._drainUnlockWaiters();
|
||||
while (this._queue.length > 0 && this._queue[0].weight <= this._value) {
|
||||
this._dispatchItem(this._queue.shift());
|
||||
this._drainUnlockWaiters();
|
||||
}
|
||||
};
|
||||
Semaphore.prototype._dispatchItem = function (item) {
|
||||
var previousValue = this._value;
|
||||
this._value -= item.weight;
|
||||
item.resolve([previousValue, this._newReleaser(item.weight)]);
|
||||
};
|
||||
Semaphore.prototype._newReleaser = function (weight) {
|
||||
var _this = this;
|
||||
var called = false;
|
||||
return function () {
|
||||
if (called)
|
||||
return;
|
||||
called = true;
|
||||
_this.release(weight);
|
||||
};
|
||||
};
|
||||
Semaphore.prototype._drainUnlockWaiters = function () {
|
||||
if (this._queue.length === 0) {
|
||||
for (var weight = this._value; weight > 0; weight--) {
|
||||
var waiters = this._weightedWaiters[weight - 1];
|
||||
if (!waiters)
|
||||
continue;
|
||||
waiters.forEach(function (waiter) { return waiter.resolve(); });
|
||||
this._weightedWaiters[weight - 1] = [];
|
||||
}
|
||||
}
|
||||
else {
|
||||
var queuedPriority_1 = this._queue[0].priority;
|
||||
for (var weight = this._value; weight > 0; weight--) {
|
||||
var waiters = this._weightedWaiters[weight - 1];
|
||||
if (!waiters)
|
||||
continue;
|
||||
var i = waiters.findIndex(function (waiter) { return waiter.priority <= queuedPriority_1; });
|
||||
(i === -1 ? waiters : waiters.splice(0, i))
|
||||
.forEach((function (waiter) { return waiter.resolve(); }));
|
||||
}
|
||||
}
|
||||
};
|
||||
Semaphore.prototype._couldLockImmediately = function (weight, priority) {
|
||||
return (this._queue.length === 0 || this._queue[0].priority < priority) &&
|
||||
weight <= this._value;
|
||||
};
|
||||
return Semaphore;
|
||||
}());
|
||||
function insertSorted(a, v) {
|
||||
var i = findIndexFromEnd(a, function (other) { return v.priority <= other.priority; });
|
||||
a.splice(i + 1, 0, v);
|
||||
}
|
||||
function findIndexFromEnd(a, predicate) {
|
||||
for (var i = a.length - 1; i >= 0; i--) {
|
||||
if (predicate(a[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
export default Semaphore;
|
||||
1
node_modules/async-mutex/es6/SemaphoreInterface.js
generated
vendored
Normal file
1
node_modules/async-mutex/es6/SemaphoreInterface.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
3
node_modules/async-mutex/es6/errors.js
generated
vendored
Normal file
3
node_modules/async-mutex/es6/errors.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export var E_TIMEOUT = new Error('timeout while waiting for mutex to become available');
|
||||
export var E_ALREADY_LOCKED = new Error('mutex already locked');
|
||||
export var E_CANCELED = new Error('request for lock canceled');
|
||||
5
node_modules/async-mutex/es6/index.js
generated
vendored
Normal file
5
node_modules/async-mutex/es6/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export { default as Mutex } from './Mutex';
|
||||
export { default as Semaphore } from './Semaphore';
|
||||
export { withTimeout } from './withTimeout';
|
||||
export { tryAcquire } from './tryAcquire';
|
||||
export * from './errors';
|
||||
8
node_modules/async-mutex/es6/tryAcquire.js
generated
vendored
Normal file
8
node_modules/async-mutex/es6/tryAcquire.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { E_ALREADY_LOCKED } from './errors';
|
||||
import { withTimeout } from './withTimeout';
|
||||
// eslint-disable-next-lisne @typescript-eslint/explicit-module-boundary-types
|
||||
export function tryAcquire(sync, alreadyAcquiredError) {
|
||||
if (alreadyAcquiredError === void 0) { alreadyAcquiredError = E_ALREADY_LOCKED; }
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return withTimeout(sync, 0, alreadyAcquiredError);
|
||||
}
|
||||
124
node_modules/async-mutex/es6/withTimeout.js
generated
vendored
Normal file
124
node_modules/async-mutex/es6/withTimeout.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { E_TIMEOUT } from './errors';
|
||||
export function withTimeout(sync, timeout, timeoutError) {
|
||||
var _this = this;
|
||||
if (timeoutError === void 0) { timeoutError = E_TIMEOUT; }
|
||||
return {
|
||||
acquire: function (weightOrPriority, priority) {
|
||||
var weight;
|
||||
if (isSemaphore(sync)) {
|
||||
weight = weightOrPriority;
|
||||
}
|
||||
else {
|
||||
weight = undefined;
|
||||
priority = weightOrPriority;
|
||||
}
|
||||
if (weight !== undefined && weight <= 0) {
|
||||
throw new Error("invalid weight ".concat(weight, ": must be positive"));
|
||||
}
|
||||
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var isTimeout, handle, ticket, release, e_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
isTimeout = false;
|
||||
handle = setTimeout(function () {
|
||||
isTimeout = true;
|
||||
reject(timeoutError);
|
||||
}, timeout);
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, (isSemaphore(sync)
|
||||
? sync.acquire(weight, priority)
|
||||
: sync.acquire(priority))];
|
||||
case 2:
|
||||
ticket = _a.sent();
|
||||
if (isTimeout) {
|
||||
release = Array.isArray(ticket) ? ticket[1] : ticket;
|
||||
release();
|
||||
}
|
||||
else {
|
||||
clearTimeout(handle);
|
||||
resolve(ticket);
|
||||
}
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
e_1 = _a.sent();
|
||||
if (!isTimeout) {
|
||||
clearTimeout(handle);
|
||||
reject(e_1);
|
||||
}
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
},
|
||||
runExclusive: function (callback, weight, priority) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var release, ticket;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
release = function () { return undefined; };
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, , 7, 8]);
|
||||
return [4 /*yield*/, this.acquire(weight, priority)];
|
||||
case 2:
|
||||
ticket = _a.sent();
|
||||
if (!Array.isArray(ticket)) return [3 /*break*/, 4];
|
||||
release = ticket[1];
|
||||
return [4 /*yield*/, callback(ticket[0])];
|
||||
case 3: return [2 /*return*/, _a.sent()];
|
||||
case 4:
|
||||
release = ticket;
|
||||
return [4 /*yield*/, callback()];
|
||||
case 5: return [2 /*return*/, _a.sent()];
|
||||
case 6: return [3 /*break*/, 8];
|
||||
case 7:
|
||||
release();
|
||||
return [7 /*endfinally*/];
|
||||
case 8: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
release: function (weight) {
|
||||
sync.release(weight);
|
||||
},
|
||||
cancel: function () {
|
||||
return sync.cancel();
|
||||
},
|
||||
waitForUnlock: function (weightOrPriority, priority) {
|
||||
var weight;
|
||||
if (isSemaphore(sync)) {
|
||||
weight = weightOrPriority;
|
||||
}
|
||||
else {
|
||||
weight = undefined;
|
||||
priority = weightOrPriority;
|
||||
}
|
||||
if (weight !== undefined && weight <= 0) {
|
||||
throw new Error("invalid weight ".concat(weight, ": must be positive"));
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
var handle = setTimeout(function () { return reject(timeoutError); }, timeout);
|
||||
(isSemaphore(sync)
|
||||
? sync.waitForUnlock(weight, priority)
|
||||
: sync.waitForUnlock(priority)).then(function () {
|
||||
clearTimeout(handle);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
isLocked: function () { return sync.isLocked(); },
|
||||
getValue: function () { return sync.getValue(); },
|
||||
setValue: function (value) { return sync.setValue(value); },
|
||||
};
|
||||
}
|
||||
function isSemaphore(sync) {
|
||||
return sync.getValue !== undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user