fix: might be wrong.
This commit is contained in:
parent
1a49bf5943
commit
fb422165cc
File diff suppressed because it is too large
Load Diff
|
@ -1,28 +1,28 @@
|
||||||
export const nonameInitialized = localStorage.getItem('noname_inited');
|
export const nonameInitialized = localStorage.getItem('noname_inited');
|
||||||
export const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized;
|
export const assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized;
|
||||||
export const GeneratorFunction = (function* () { }).constructor;
|
export const GeneratorFunction = (function* () { }).constructor;
|
||||||
export const AsyncFunction = (async function () { }).constructor;
|
export const AsyncFunction = (async function () { }).constructor;
|
||||||
export const userAgent = navigator.userAgent.toLowerCase();
|
export const userAgent = navigator.userAgent.toLowerCase();
|
||||||
export { Mutex } from './mutex.js';
|
export { Mutex } from './mutex.js';
|
||||||
export const characterDefaultPicturePath = "image/character/default_silhouette_";
|
export const characterDefaultPicturePath = "image/character/default_silhouette_";
|
||||||
|
|
||||||
// 我靠循环引用问题在这?
|
// 我靠循环引用问题在这?
|
||||||
// export * as config from './config.js'
|
// export * as config from './config.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不能被new的类
|
* 不能被new的类
|
||||||
*/
|
*/
|
||||||
export class Uninstantable {
|
export class Uninstantable {
|
||||||
constructor() {
|
constructor() {
|
||||||
throw new TypeError(`${new.target.name} is not a constructor`);
|
throw new TypeError(`${new.target.name} is not a constructor`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param { number } ms
|
* @param { number } ms
|
||||||
* @returns { Promise<void> }
|
* @returns { Promise<void> }
|
||||||
*/
|
*/
|
||||||
export function delay(ms) {
|
export function delay(ms) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,58 +1,58 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class Mutex {
|
export class Mutex {
|
||||||
/**
|
/**
|
||||||
* @type {'locked' | 'unlocked'}
|
* @type {'locked' | 'unlocked'}
|
||||||
*/
|
*/
|
||||||
#status;
|
#status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {null | Promise<void>}
|
* @type {null | Promise<void>}
|
||||||
*/
|
*/
|
||||||
#promise;
|
#promise;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {null | function(): void}
|
* @type {null | function(): void}
|
||||||
*/
|
*/
|
||||||
#resolve;
|
#resolve;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#status = 'unlocked';
|
this.#status = 'unlocked';
|
||||||
this.#promise = null;
|
this.#promise = null;
|
||||||
this.#resolve = null;
|
this.#resolve = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async lock() {
|
async lock() {
|
||||||
switch (this.#status) {
|
switch (this.#status) {
|
||||||
case 'locked':
|
case 'locked':
|
||||||
await this.#promise;
|
await this.#promise;
|
||||||
|
|
||||||
case 'unlocked':
|
case 'unlocked':
|
||||||
this.#status = 'locked';
|
this.#status = 'locked';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
({ promise: this.#promise, resolve: this.#resolve } = Promise.withResolvers())
|
({ promise: this.#promise, resolve: this.#resolve } = Promise.withResolvers())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock() {
|
unlock() {
|
||||||
if (this.#status === 'unlocked') throw new Error('This Mutex is not locked.');
|
if (this.#status === 'unlocked') throw new Error('This Mutex is not locked.');
|
||||||
|
|
||||||
this.#status = 'unlocked';
|
this.#status = 'unlocked';
|
||||||
if (this.#resolve) this.#resolve();
|
if (this.#resolve) this.#resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {function(): void | Promise<void>} content
|
* @param {function(): void | Promise<void>} content
|
||||||
*/
|
*/
|
||||||
async scoped(content) {
|
async scoped(content) {
|
||||||
try {
|
try {
|
||||||
await this.lock();
|
await this.lock();
|
||||||
await content();
|
await content();
|
||||||
} finally {
|
} finally {
|
||||||
this.unlock();
|
this.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue