2019-09-09 19:07:56 +08:00
|
|
|
|
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
|
|
|
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
|
|
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.Scripting;
|
2020-05-05 18:46:43 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2019-09-09 19:07:56 +08:00
|
|
|
|
using Unity.Collections;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine.TestTools;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
2020-05-05 18:46:43 +08:00
|
|
|
|
namespace Cysharp.Threading.TasksTests
|
2019-09-09 19:07:56 +08:00
|
|
|
|
{
|
|
|
|
|
public class WhenAnyTest
|
|
|
|
|
{
|
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator WhenAnyCanceled() => UniTask.ToCoroutine(async () =>
|
|
|
|
|
{
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
var successDelayTask = UniTask.Delay(TimeSpan.FromSeconds(1));
|
|
|
|
|
var cancelTask = UniTask.Delay(TimeSpan.FromSeconds(1), cancellationToken: cts.Token);
|
|
|
|
|
cts.CancelAfterSlim(200);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var r = await UniTask.WhenAny(new[] { successDelayTask, cancelTask });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.Should().BeAssignableTo<OperationCanceledException>();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|