reformat code
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user