fix: 비동기 대응 로직 추가

This commit is contained in:
2023-03-09 02:20:11 +09:00
parent 6d00966d15
commit 7425722c39
2 changed files with 19 additions and 16 deletions
+16 -14
View File
@@ -72,7 +72,6 @@
declare const staticValues: {
serverName: string;
serverNick: string;
serverCnt: number;
serverID: string;
mapName: string;
unitSet: string;
@@ -91,7 +90,7 @@ import { formatLog } from "@/utilGame/formatLog";
import type { ExecuteResponse } from "./defs/API/Global";
import { delay } from "./util/delay";
const { serverName, serverNick, serverCnt, serverID } = staticValues;
const { serverName, serverNick, serverID } = staticValues;
const asyncReady = ref(false);
const gameConstStore = ref<GameConstStore>();
@@ -108,21 +107,15 @@ const storeP = getGameConstStore().then((store) => {
gameConstStore.value = store;
});
const responseP = ref<
Promise<
| ExecuteResponse
| (InvalidResponse & {
reqRefresh?: boolean;
})
>
>();
let responseLock = false;
async function tryRefresh() {
if (responseP.value !== undefined) {
if (responseLock) {
return;
}
try {
responseP.value = SammoAPI.Global.ExecuteEngine({ serverID }, true).then(
responseLock = true;
const responseP = SammoAPI.Global.ExecuteEngine({ serverID }, true).then(
(response) => {
if (response.result) {
lastExecuted.value = parseTime(response.lastExecuted);
@@ -133,8 +126,8 @@ async function tryRefresh() {
);
//TODO: 갱신 알림 띄우기
const response = await Promise.race([delay(3000), responseP.value]);
responseP.value = undefined;
const response = await Promise.race([delay(3000), responseP]);
responseLock = false;
if(response === undefined){
//timeout이지만 일단 갱신한다.
@@ -164,6 +157,7 @@ async function tryRefresh() {
//TODO: 서버와 클라이언트 버전이 다르다면 갱신 필요
} catch (e) {
responseLock = false;
//매우 심각한 버그
console.error(e);
alert(`서버 갱신 실패: ${e}`);
@@ -182,12 +176,19 @@ const generalRecords = ref(new Denque<[number, string]>());
const globalRecords = ref(new Denque<[number, string]>());
const worldHistory = ref(new Denque<[number, string]>());
let recordLock = false;
watch(refreshCounter, async () => {
if(recordLock){
return;
}
try {
recordLock = true;
const response = await SammoAPI.Global.GetRecentRecord({
lastGeneralRecordID: lastGeneralRecordID.value,
lastWorldHistoryID: lastWorldHistoryID.value,
});
recordLock = false;
if (response.flushGeneral) {
generalRecords.value = new Denque<[number, string]>();
@@ -243,6 +244,7 @@ watch(refreshCounter, async () => {
worldHistory.value.unshift([id, record]);
}
} catch (e) {
recordLock = false;
console.error(e);
toasts.danger({
title: "최근 기록 갱신 실패",
+3 -2
View File
@@ -6,6 +6,8 @@ include "lib.php";
include "func.php";
//로그인 검사
Session::requireGameLogin()->setReadOnly();
//턴 실행 대기 및 갱신 증가는 API에서
//TODO: 내 정보도 API에서, 사망 여부도
@@ -29,8 +31,7 @@ include "func.php";
<title><?= UniqueConst::$serverName ?>: 메인</title>
<?= WebUtil::printStaticValues([
'staticValues' => [
'serverName' => $serverName,
'serverCnt' => $serverCnt,
'serverName' => UniqueConst::$serverName,
'serverNick' => DB::prefix(),
'serverID' => UniqueConst::$serverID,
'mapName' => GameConst::$mapName,