[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>
|
||||
|
||||
Reference in New Issue
Block a user