pipeline 스레드 적용
This commit is contained in:
@@ -158,7 +158,7 @@ namespace UVC.Data
|
||||
/// 모든 HTTP 요청 처리는 백그라운드 스레드에서 수행되며, 핸들러만 메인 스레드에서 호출됩니다.
|
||||
/// </remarks>
|
||||
/// <exception cref="KeyNotFoundException">지정된 키가 등록되어 있지 않은 경우</exception>
|
||||
public async UniTask Excute(string key, bool switchToMainThread = false)
|
||||
public async UniTask Excute(string key)
|
||||
{
|
||||
if (!infoList.ContainsKey(key))
|
||||
{
|
||||
@@ -179,6 +179,7 @@ namespace UVC.Data
|
||||
{
|
||||
// 단일 실행 로직 호출
|
||||
await ExecuteSingle(key, info);
|
||||
await UniTask.SwitchToMainThread();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -187,15 +188,11 @@ namespace UVC.Data
|
||||
StartRepeat(key).Forget();
|
||||
}
|
||||
}
|
||||
finally
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ExecuteSingle 또는 StartRepeat.Forget() 후 메인 스레드로 복귀하는 것은 선택 사항
|
||||
// 여기서는 원래 실행 컨텍스트로 돌아가기 위해 메인 스레드로 전환
|
||||
// 만약 계속해서 백그라운드 스레드에서 실행하려면 이 코드를 제거할 수 있음
|
||||
if (switchToMainThread)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
}
|
||||
// 예외가 발생한 경우에도 메인 스레드로 복귀
|
||||
await UniTask.SwitchToMainThread();
|
||||
throw; // 예외 재발생
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,13 +233,13 @@ namespace UVC.Data
|
||||
try
|
||||
{
|
||||
string result = string.Empty;
|
||||
if (!UseMockup)
|
||||
if (UseMockup)
|
||||
{
|
||||
result = await HttpRequester.Request<string>(info.Url, info.Method, info.Body, info.Headers);
|
||||
result = await MockHttpRequester.Request<string>(info.Url, info.Method, info.Body, info.Headers);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await MockHttpRequester.Request<string>(info.Url, info.Method, info.Body, info.Headers);
|
||||
result = await HttpRequester.Request<string>(info.Url, info.Method, info.Body, info.Headers);
|
||||
}
|
||||
|
||||
// 응답 처리 전에 다시 취소 요청 확인
|
||||
@@ -267,10 +264,8 @@ namespace UVC.Data
|
||||
string errorMessage = responseResult.Message!;
|
||||
|
||||
// UI 스레드에서 실패 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.FailHandler.Invoke(errorMessage);
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.FailHandler.Invoke(errorMessage);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -293,10 +288,8 @@ namespace UVC.Data
|
||||
if (info.FailHandler != null)
|
||||
{
|
||||
// UI 스레드에서 실패 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -310,10 +303,8 @@ namespace UVC.Data
|
||||
if (info.FailHandler != null)
|
||||
{
|
||||
// UI 스레드에서 실패 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -350,10 +341,8 @@ namespace UVC.Data
|
||||
if (info.FailHandler != null)
|
||||
{
|
||||
// UI 스레드에서 실패 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -368,10 +357,8 @@ namespace UVC.Data
|
||||
if (info.FailHandler != null)
|
||||
{
|
||||
// UI 스레드에서 실패 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.FailHandler.Invoke("Data is not Valid");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -441,15 +428,14 @@ namespace UVC.Data
|
||||
// 로컬 변수로 복사하여 클로저에서 안전하게 사용
|
||||
var handlerData = dataObject;
|
||||
// UI 스레드에서 성공 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.SuccessHandler.Invoke(handlerData);
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.SuccessHandler.Invoke(handlerData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (dataObject != null)
|
||||
{
|
||||
if (info.SuccessHandler != null)
|
||||
@@ -457,10 +443,8 @@ namespace UVC.Data
|
||||
// 로컬 변수로 복사하여 클로저에서 안전하게 사용
|
||||
var handlerData = dataObject;
|
||||
// UI 스레드에서 성공 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.SuccessHandler.Invoke(handlerData);
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.SuccessHandler.Invoke(handlerData);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -468,10 +452,8 @@ namespace UVC.Data
|
||||
if (info.FailHandler != null)
|
||||
{
|
||||
// UI 스레드에서 실패 핸들러 호출
|
||||
MainThreadDispatcher.Instance.SendToMainThread(() =>
|
||||
{
|
||||
info.FailHandler.Invoke("Data is Null");
|
||||
});
|
||||
await UniTask.SwitchToMainThread();
|
||||
info.FailHandler.Invoke("Data is Null");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,7 +513,6 @@ namespace UVC.Data
|
||||
if (!infoList.ContainsKey(key))
|
||||
{
|
||||
throw new KeyNotFoundException($"No HTTP request found with key '{key}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
HttpPipeLineInfo info = infoList[key];
|
||||
@@ -619,7 +600,7 @@ namespace UVC.Data
|
||||
/// </remarks>
|
||||
public async UniTask StopRepeat(string key)
|
||||
{
|
||||
CancellationTokenSource cts = null;
|
||||
CancellationTokenSource? cts = null;
|
||||
lock (repeatTokenSources) // 스레드 안전성 확보
|
||||
{
|
||||
if (repeatTokenSources.TryGetValue(key, out cts) && !cts.IsCancellationRequested)
|
||||
|
||||
Reference in New Issue
Block a user