Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions GFramework.Core.Tests/extensions/AsyncExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AsyncExtensionsTests
public async Task WithTimeout_Should_Return_Result_When_Task_Completes_Before_Timeout()
{
// Act
var result = await AsyncExtensions.WithTimeout(
var result = await AsyncExtensions.WithTimeoutAsync(
_ => Task.FromResult(42),
TimeSpan.FromSeconds(1));

Expand All @@ -34,7 +34,7 @@ public void WithTimeout_Should_Throw_TimeoutException_When_Task_Exceeds_Timeout(
{
// Act & Assert
Assert.ThrowsAsync<TimeoutException>(async () =>
await AsyncExtensions.WithTimeout(
await AsyncExtensions.WithTimeoutAsync(
async ct =>
{
await Task.Delay(TimeSpan.FromSeconds(2), ct);
Expand All @@ -54,7 +54,7 @@ public void WithTimeout_Should_Throw_OperationCanceledException_When_Cancellatio
cts.Cancel();
// Act & Assert
Assert.ThrowsAsync<TaskCanceledException>(async () =>
await AsyncExtensions.WithTimeout(
await AsyncExtensions.WithTimeoutAsync(
async ct =>
{
await Task.Delay(TimeSpan.FromSeconds(2), ct);
Expand All @@ -75,7 +75,7 @@ public void WithTimeout_Should_Cancel_Inner_Task_When_Timeout_Elapses()

// Act & Assert
Assert.ThrowsAsync<TimeoutException>(async () =>
await AsyncExtensions.WithTimeout(
await AsyncExtensions.WithTimeoutAsync(
async ct =>
{
try
Expand Down Expand Up @@ -104,7 +104,7 @@ public async Task WithTimeout_NoResult_Should_Complete_When_Task_Completes_Befor
var stopwatch = Stopwatch.StartNew();

// Act
await AsyncExtensions.WithTimeout(
await AsyncExtensions.WithTimeoutAsync(
_ => Task.CompletedTask,
TimeSpan.FromSeconds(1));
stopwatch.Stop();
Expand All @@ -122,7 +122,7 @@ public void WithTimeout_NoResult_Should_Throw_TimeoutException_When_Task_Exceeds
{
// Act & Assert
Assert.ThrowsAsync<TimeoutException>(async () =>
await AsyncExtensions.WithTimeout(
await AsyncExtensions.WithTimeoutAsync(
ct => Task.Delay(TimeSpan.FromSeconds(2), ct),
TimeSpan.FromMilliseconds(100)));
}
Expand All @@ -138,7 +138,7 @@ public void WithTimeout_NoResult_Should_Cancel_Inner_Task_When_Timeout_Elapses()

// Act & Assert
Assert.ThrowsAsync<TimeoutException>(async () =>
await AsyncExtensions.WithTimeout(
await AsyncExtensions.WithTimeoutAsync(
async ct =>
{
try
Expand Down Expand Up @@ -171,7 +171,7 @@ public async Task WithRetry_Should_Return_Result_When_Task_Succeeds()
};

// Act
var result = await taskFactory.WithRetry(3, TimeSpan.FromMilliseconds(10));
var result = await taskFactory.WithRetryAsync(3, TimeSpan.FromMilliseconds(10));

// Assert
Assert.That(result, Is.EqualTo(42));
Expand All @@ -195,7 +195,7 @@ public async Task WithRetry_Should_Retry_On_Failure()
};

// Act
var result = await taskFactory.WithRetry(3, TimeSpan.FromMilliseconds(10));
var result = await taskFactory.WithRetryAsync(3, TimeSpan.FromMilliseconds(10));

// Assert
Assert.That(result, Is.EqualTo(42));
Expand All @@ -218,7 +218,7 @@ public void WithRetry_Should_Throw_AggregateException_When_All_Retries_Fail()

// Act & Assert
Assert.ThrowsAsync<AggregateException>(async () =>
await taskFactory.WithRetry(2, TimeSpan.FromMilliseconds(10)));
await taskFactory.WithRetryAsync(2, TimeSpan.FromMilliseconds(10)));
}

/// <summary>
Expand All @@ -237,7 +237,7 @@ public async Task WithRetry_Should_Respect_ShouldRetry_Predicate()

// Act & Assert
Assert.ThrowsAsync<AggregateException>(async () =>
await taskFactory.WithRetry(3, TimeSpan.FromMilliseconds(10),
await taskFactory.WithRetryAsync(3, TimeSpan.FromMilliseconds(10),
ex => ex is not ArgumentException));

await Task.Delay(50); // 等待任务完成
Expand Down Expand Up @@ -287,7 +287,7 @@ public async Task WithFallback_Should_Return_Result_When_Task_Succeeds()
var task = Task.FromResult(42);

// Act
var result = await task.WithFallback(_ => -1);
var result = await task.WithFallbackAsync(_ => -1);

// Assert
Assert.That(result, Is.EqualTo(42));
Expand All @@ -303,7 +303,7 @@ public async Task WithFallback_Should_Return_Fallback_Value_When_Task_Fails()
var task = Task.FromException<int>(new InvalidOperationException("Test error"));

// Act
var result = await task.WithFallback(_ => -1);
var result = await task.WithFallbackAsync(_ => -1);

// Assert
Assert.That(result, Is.EqualTo(-1));
Expand All @@ -321,7 +321,7 @@ public async Task WithFallback_Should_Pass_Exception_To_Fallback()
Exception? capturedEx = null;

// Act
await task.WithFallback(ex =>
await task.WithFallbackAsync(ex =>
{
capturedEx = ex;
return -1;
Expand Down
10 changes: 5 additions & 5 deletions GFramework.Core/extensions/AsyncExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public static class AsyncExtensions
/// <exception cref="OperationCanceledException">当操作被取消时抛出</exception>
/// <example>
/// <code>
/// var result = await WithTimeout(
/// var result = await WithTimeoutAsync(
/// ct => SomeAsyncOperation(ct),
/// TimeSpan.FromSeconds(5));
/// </code>
/// </example>
public static async Task<T> WithTimeout<T>(
public static async Task<T> WithTimeoutAsync<T>(
Func<CancellationToken, Task<T>> taskFactory,
TimeSpan timeout,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -66,7 +66,7 @@ public static async Task<T> WithTimeout<T>(
/// <exception cref="ArgumentNullException">当 taskFactory 为 null 时抛出</exception>
/// <exception cref="TimeoutException">当任务超时时抛出</exception>
/// <exception cref="OperationCanceledException">当操作被取消时抛出</exception>
public static async Task WithTimeout(
public static async Task WithTimeoutAsync(
Func<CancellationToken, Task> taskFactory,
TimeSpan timeout,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -108,10 +108,10 @@ public static async Task WithTimeout(
/// <example>
/// <code>
/// var result = await RiskyOperation()
/// .WithFallback(ex => DefaultValue);
/// .WithFallbackAsync(ex => DefaultValue);
/// </code>
/// </example>
public static async Task<T> WithFallback<T>(this Task<T> task, Func<Exception, T> fallback)
public static async Task<T> WithFallbackAsync<T>(this Task<T> task, Func<Exception, T> fallback)
{
ArgumentNullException.ThrowIfNull(task);
ArgumentNullException.ThrowIfNull(fallback);
Expand Down
4 changes: 2 additions & 2 deletions GFramework.Core/functional/async/AsyncFunctionalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public static class AsyncFunctionalExtensions
/// <example>
/// <code>
/// var result = await (() => UnreliableOperation())
/// .WithRetry(maxRetries: 3, delay: TimeSpan.FromSeconds(1));
/// .WithRetryAsync(maxRetries: 3, delay: TimeSpan.FromSeconds(1));
/// </code>
/// </example>
public static async Task<T> WithRetry<T>(
public static async Task<T> WithRetryAsync<T>(
this Func<Task<T>> taskFactory,
int maxRetries,
TimeSpan delay,
Expand Down
2 changes: 1 addition & 1 deletion GFramework.Godot/architecture/AbstractArchitecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected async Task InstallGodotModule<TModule>(TModule module) where TModule :
throw new InvalidOperationException("Anchor not initialized");

// 等待锚点准备就绪
await _anchor.WaitUntilReady();
await _anchor.WaitUntilReadyAsync();

// 延迟调用将扩展节点添加为锚点的子节点
_anchor.CallDeferred(Node.MethodName.AddChild, module.Node);
Expand Down
6 changes: 3 additions & 3 deletions GFramework.Godot/extensions/NodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void FreeX(this Node? node)
/// </summary>
/// <param name="node">要等待其准备就绪的节点</param>
/// <returns>表示异步操作的任务</returns>
public static async Task WaitUntilReady(this Node node)
public static async Task WaitUntilReadyAsync(this Node node)
{
if (!node.IsInsideTree()) await node.ToSignal(node, Node.SignalName.Ready);
}
Expand Down Expand Up @@ -173,10 +173,10 @@ public static T GetOrCreateNode<T>(this Node node, string path)
/// <param name="parent">父节点</param>
/// <param name="child">要添加的子节点</param>
/// <returns>异步任务</returns>
public static async Task AddChildX(this Node parent, Node child)
public static async Task AddChildXAsync(this Node parent, Node child)
{
parent.AddChild(child);
await child.WaitUntilReady();
await child.WaitUntilReadyAsync();
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions docs/zh-CN/godot/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ node.QueueFreeX(); // 延迟释放
node.FreeX(); // 立即释放

// 等待节点就绪
await node.WaitUntilReady();
await node.WaitUntilReadyAsync();

// 检查节点有效性
if (node.IsValidNode()) Console.WriteLine("节点有效");
Expand Down Expand Up @@ -92,7 +92,7 @@ node.ForEachChild<Sprite2D>(sprite => {
var root = node.GetRootNodeX();

// 异步添加子节点
await parent.AddChildX(childNode);
await parent.AddChildXAsync(childNode);

// 设置场景树暂停状态
node.Paused(true); // 暂停
Expand Down Expand Up @@ -178,7 +178,7 @@ public class GameManager : Node

// 安全添加子节点
var player = new Player();
await AddChildX(player);
await AddChildXAsync(player);

// 查找并配置玩家
var sprite = player.FindChildX<Sprite2D>("Sprite");
Expand Down Expand Up @@ -237,7 +237,7 @@ public class SceneManager : Node
var instance = packedScene.Instantiate<T>();

// 等待场景加载完成
await instance.WaitUntilReady();
await instance.WaitUntilReadyAsync();

return instance;
}
Expand All @@ -250,7 +250,7 @@ public class SceneManager : Node
ForEachChild<Node>(child => child.QueueFreeX());

// 加载新场景
await AddChildX(newScene);
await AddChildXAsync(newScene);

// 设置输入处理
newScene.SetInputAsHandled();
Expand Down Expand Up @@ -310,7 +310,7 @@ var button = node.FindChild("Button") as Button;

```csharp
// ✅ 推荐:等待节点就绪
await child.WaitUntilReady();
await child.WaitUntilReadyAsync();

// ❌ 避免:假设节点已就绪
child.DoSomething();
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/godot/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ var bullet = bulletScene.Instantiate<Bullet>();
AddChildX(bullet);

// 等待节点准备就绪
await bullet.WaitUntilReady();
await bullet.WaitUntilReadyAsync();

// 获取父节点
var parent = GetParentX<GameLevel>();
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/tutorials/godot-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public partial class SafeNodeOperations : Node
AddChildX(bullet);

// 安全的异步操作
this.WaitUntilReady()
this.WaitUntilReadyAsync()
.Then(() => {
// 节点准备就绪后的操作
InitializeAfterReady();
Expand Down
Loading