Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod TerminateAsync return type UniTaskVoid and remove parameter CancellationToken #134

Merged
merged 1 commit into from
Jan 10, 2025
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
16 changes: 7 additions & 9 deletions Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// Copyright (c) 2023-2025 DeNA Co., Ltd.
// This software is released under the MIT License.

using System;
using System.Collections;
using System.Threading;
using Cysharp.Threading.Tasks;
using DeNA.Anjin.Settings;
using DeNA.Anjin.Utilities;
Expand All @@ -28,10 +27,9 @@ public interface ITerminatable
/// <param name="message">Log message string or terminate message</param>
/// <param name="stackTrace">Stack trace when terminate by the log message</param>
/// <param name="reporting">Call Reporter if true</param>
/// <param name="token">Cancellation token</param>
/// <returns>A task awaits termination get completed</returns>
UniTask TerminateAsync(ExitCode exitCode, string message = null, string stackTrace = null,
bool reporting = true, CancellationToken token = default);
UniTaskVoid TerminateAsync(ExitCode exitCode, string message = null, string stackTrace = null,
bool reporting = true);
}

/// <summary>
Expand Down Expand Up @@ -144,7 +142,7 @@ private void DispatchByLoadedScenes()
private IEnumerator Lifespan(int timeoutSec, ExitCode exitCode, string message)
{
yield return new WaitForSecondsRealtime(timeoutSec);
yield return UniTask.ToCoroutine(() => TerminateAsync(exitCode, message));
TerminateAsync(exitCode, message).Forget();
}

private void OnDestroy()
Expand All @@ -157,8 +155,8 @@ private void OnDestroy()
}

/// <inheritdoc/>
public async UniTask TerminateAsync(ExitCode exitCode, string message = null, string stackTrace = null,
bool reporting = true, CancellationToken token = default)
public async UniTaskVoid TerminateAsync(ExitCode exitCode, string message = null, string stackTrace = null,
bool reporting = true)
{
if (_isTerminating)
{
Expand All @@ -176,7 +174,7 @@ public async UniTask TerminateAsync(ExitCode exitCode, string message = null, st

if (reporting && _state.IsRunning && _settings.Reporter != null)
{
await _settings.Reporter.PostReportAsync(message, stackTrace, exitCode, token);
await _settings.Reporter.PostReportAsync(message, stackTrace, exitCode);
}

Destroy(this.gameObject);
Expand Down
14 changes: 10 additions & 4 deletions Tests/Runtime/AutopilotTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// Copyright (c) 2023-2025 DeNA Co., Ltd.
// This software is released under the MIT License.

using System.Collections.Generic;
Expand Down Expand Up @@ -97,7 +97,9 @@ public async Task TerminateAsync_DestroyedAutopilotAndAgentObjects()
var agents = AgentInspector.Instances;
Assume.That(agents, Is.Not.Empty, "Agents are running");

await autopilot.TerminateAsync(ExitCode.Normally, reporting: false);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
autopilot.TerminateAsync(ExitCode.Normally, reporting: false);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
await UniTask.NextFrame(); // wait for destroy

autopilot = Object.FindObjectOfType<Autopilot>(); // re-find after terminated
Expand Down Expand Up @@ -138,7 +140,9 @@ public async Task TerminateAsync_NoReporting_NotCallReporter()
await UniTask.Delay(500); // wait for launch

var autopilot = Autopilot.Instance;
await autopilot.TerminateAsync(ExitCode.Normally, null, null, false);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
autopilot.TerminateAsync(ExitCode.Normally, null, null, false);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

Assert.That(spyReporter.IsCalled, Is.False);
}
Expand All @@ -153,7 +157,9 @@ public async Task TerminateAsync_Reporting_CallReporter()
await UniTask.Delay(500); // wait for launch

var autopilot = Autopilot.Instance;
await autopilot.TerminateAsync(ExitCode.Normally, "message", "stack trace", true);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
autopilot.TerminateAsync(ExitCode.Normally, "message", "stack trace", true);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

Assert.That(spyReporter.IsCalled, Is.True);
Assert.That(spyReporter.Arguments["exitCode"], Is.EqualTo("Normally"));
Expand Down
7 changes: 3 additions & 4 deletions Tests/Runtime/TestDoubles/SpyTerminatable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023-2024 DeNA Co., Ltd.
// Copyright (c) 2023-2025 DeNA Co., Ltd.
// This software is released under the MIT License.

using System.Threading;
using Cysharp.Threading.Tasks;

namespace DeNA.Anjin.TestDoubles
Expand All @@ -14,8 +13,8 @@ public class SpyTerminatable : ITerminatable
public string CapturedStackTrace { get; private set; }
public bool CapturedReporting { get; private set; }

public async UniTask TerminateAsync(ExitCode exitCode, string message = null, string stackTrace = null,
bool reporting = true, CancellationToken token = default)
public async UniTaskVoid TerminateAsync(ExitCode exitCode, string message = null, string stackTrace = null,
bool reporting = true)
{
IsCalled = true;
CapturedExitCode = exitCode;
Expand Down
Loading