[U] sync with ft
This commit is contained in:
@@ -71,6 +71,49 @@ namespace tysdk
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置已注册 callback 的超时时间:取消先前安排的延时 <see cref="CancellationTokenSource.Cancel"/>,
|
||||
/// 并从<strong>当前时刻</strong>起在 <paramref name="newTimeout"/> 后触发取消(与构造时传入的延时等价,见 <see cref="CancellationTokenSource.CancelAfter(System.TimeSpan)"/>)。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Callback 数据类型</typeparam>
|
||||
/// <param name="newTimeout">新的超时时间;若需立即按超时处理可使用 <see cref="TimeSpan.Zero"/></param>
|
||||
/// <returns>找到未完成 pending 并成功重置则为 true</returns>
|
||||
public bool ResetCallbackTimeout<T>(TimeSpan newTimeout) where T : class
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException(nameof(TYSDKCallbackManager));
|
||||
|
||||
var callbackId = typeof(T).Name;
|
||||
|
||||
if (!_callbacks.TryGetValue(callbackId, out var entry))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[TYSDKCallbackManager] No pending callback found for type: {callbackId}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entry.Task.IsCompleted)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[TYSDKCallbackManager] Callback {callbackId} already completed, cannot reset timeout");
|
||||
return false;
|
||||
}
|
||||
|
||||
var cts = entry.CancellationTokenSource;
|
||||
if (cts == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
cts.CancelAfter(newTimeout);
|
||||
UnityEngine.Debug.Log($"[TYSDKCallbackManager] Reset timeout for {callbackId} to {newTimeout.TotalSeconds}s");
|
||||
return true;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[TYSDKCallbackManager] CancellationTokenSource already disposed for {callbackId}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 触发callback
|
||||
/// </summary>
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace tysdk
|
||||
|___/
|
||||
=================================================*/
|
||||
|
||||
private bool _payFirstNegativeHandled;
|
||||
|
||||
//public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count, string pType, string price_amount_micros =null)
|
||||
public async Task<PaymentInfo> Pay(SKUDetail prod, int count, float usdprice, JObject purchaseInfo)
|
||||
{
|
||||
@@ -76,6 +78,10 @@ namespace tysdk
|
||||
Debug.LogWarning($"[TYSdkFacade::Pay] Faild {e.Message}");
|
||||
return new PaymentInfo(){code = "-1"};
|
||||
}
|
||||
finally
|
||||
{
|
||||
_payFirstNegativeHandled = false;
|
||||
}
|
||||
|
||||
|
||||
#elif UNITY_IOS
|
||||
@@ -95,6 +101,10 @@ namespace tysdk
|
||||
Debug.LogWarning($"[TYSdkFacade::Pay] Faild {e.Message}");
|
||||
return new PaymentInfo(){code = "-1"};
|
||||
}
|
||||
finally
|
||||
{
|
||||
_payFirstNegativeHandled = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -108,7 +118,16 @@ namespace tysdk
|
||||
result.msg = jresult["errStr"].ToString();
|
||||
if(result.code == "-1")
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] pay failed: waiting next pay callback");
|
||||
if (!_payFirstNegativeHandled)
|
||||
{
|
||||
_payFirstNegativeHandled = true;
|
||||
TYSDKCallbackManager.Instance.ResetCallbackTimeout<PaymentInfo>(TimeSpan.FromSeconds(5));
|
||||
Debug.Log("[TYSdkFacade] pay failed (first time): reset timeout to 5s, waiting next pay callback");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] pay failed: waiting next pay callback");
|
||||
}
|
||||
return;
|
||||
}
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
|
||||
Reference in New Issue
Block a user