From 234890a367421561f82439a4fc5c5cd1d225b7a8 Mon Sep 17 00:00:00 2001 From: yvan Date: Sun, 27 Jul 2025 14:40:04 +0800 Subject: [PATCH] getLock --- src/core/script/LCCScript.ts | 14 +++++++++++--- src/types/LCC.d.ts | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/core/script/LCCScript.ts b/src/core/script/LCCScript.ts index bc53c17..62fad8c 100644 --- a/src/core/script/LCCScript.ts +++ b/src/core/script/LCCScript.ts @@ -56,6 +56,14 @@ export default class LCCScript implements LCC { }) } + getLock(): { lock: Promise, release: () => void } { + const obj = Promise.withResolvers() + return { + lock: obj.promise, + release: obj.resolve + } + } + // 从后台读取所有库存 async queryInv(option: InvQueryCondition = {}): Promise> { return Request.request.post('/api/workbench/InvController@queryInv', { @@ -96,7 +104,7 @@ export default class LCCScript implements LCC { * 保存当前项目所有脚本 * @param scriptList */ - saveScripts(scriptList: { name: string, content: string }[]): Promise>{ + saveScripts(scriptList: { name: string, content: string }[]): Promise> { if (!worldModel.state.project_uuid) { return Promise.reject(new Error('Project UUID is not set.')) } @@ -110,13 +118,13 @@ export default class LCCScript implements LCC { /** * 同步当前项目所有脚本 */ - syncScripts(): Promise>{ + syncScripts(): Promise> { if (!worldModel.state.project_uuid) { return Promise.reject(new Error('Project UUID is not set.')) } return Request.request.post('/api/workbench/LccController@syncScripts', { - projectUUID: worldModel.state.project_uuid, + projectUUID: worldModel.state.project_uuid }) } diff --git a/src/types/LCC.d.ts b/src/types/LCC.d.ts index 29fec50..ac1e7c9 100644 --- a/src/types/LCC.d.ts +++ b/src/types/LCC.d.ts @@ -14,6 +14,11 @@ declare interface LCC { sleep(timeOfMs: number = 1000): Promise /** + * 获取锁 + */ + getLock(): { lock: Promise, release: () => void } + + /** * 读取当前项目所有库存, 并放到 Model 上 */ queryInv(option: InvQueryCondition = {}): Promise>