reformat code

This commit is contained in:
yhh
2020-07-28 16:25:20 +08:00
parent 5994f0bee3
commit 514572f291
103 changed files with 2896 additions and 2839 deletions

View File

@@ -13,24 +13,25 @@ const nextTick = fn => {
class LockUtils {
private _keyX: string;
private _keyY: string;
constructor(key){
constructor(key) {
this._keyX = `mutex_key_${key}_X`;
this._keyY = `mutex_key_${key}_Y`;
}
public lock(){
public lock() {
return new Promise((resolve, reject) => {
const fn = () => {
setItem(this._keyX, THREAD_ID);
if (!getItem(this._keyY) === null){
if (!getItem(this._keyY) === null) {
// restart
nextTick(fn);
}
setItem(this._keyY, THREAD_ID);
if (getItem(this._keyX) !== THREAD_ID){
if (getItem(this._keyX) !== THREAD_ID) {
// delay
setTimeout(()=>{
if (getItem(this._keyY) !== THREAD_ID){
setTimeout(() => {
if (getItem(this._keyY) !== THREAD_ID) {
// restart
nextTick(fn);
return;