Compare commits

..

2 Commits

Author SHA1 Message Date
hadashiA 55bc644563
Merge bd0fe8e77d into 548d56e654 2023-09-01 09:55:17 +00:00
hadashiA bd0fe8e77d Fix TriggerEvent problem with iterate breaking on Remove when it has multiple handlers 2023-09-01 18:55:08 +09:00
4 changed files with 73 additions and 12 deletions

View File

@ -2,12 +2,7 @@
using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Channels;
using Cysharp.Threading.Tasks.Linq;
using System.Threading.Tasks;
using Xunit;
namespace NetCoreTests

View File

@ -85,9 +85,9 @@ namespace Cysharp.Threading.Tasks
{
LogError(ex);
}
iteratingNode = null;
var next = h == iteratingNode ? h.Next : iteratingNode;
var next = h.Next;
Remove(h);
h = next;
}
@ -119,9 +119,9 @@ namespace Cysharp.Threading.Tasks
{
LogError(ex);
}
var next = h == iteratingNode ? h.Next : iteratingNode;
iteratingNode = null;
var next = h.Next;
Remove(h);
h = next;
}
@ -153,9 +153,9 @@ namespace Cysharp.Threading.Tasks
{
LogError(ex);
}
var next = h == iteratingNode ? h.Next : iteratingNode;
iteratingNode = null;
var next = h.Next;
Remove(h);
h = next;
}
@ -226,7 +226,7 @@ namespace Cysharp.Threading.Tasks
public void Remove(ITriggerHandler<T> handler)
{
if (handler == null) throw new ArgumentNullException(nameof(handler));
var prev = handler.Prev;
var next = handler.Next;

View File

@ -0,0 +1,63 @@
using Cysharp.Threading.Tasks;
using FluentAssertions;
using System;
using System.Collections;
using System.Threading;
using UnityEngine.TestTools;
namespace Cysharp.Threading.TasksTests
{
public class AsyncReactivePropertyTest
{
private int _callCounter;
[UnityTest]
public IEnumerator WaitCancelWait() => UniTask.ToCoroutine(async () =>
{
// Test case for https://github.com/Cysharp/UniTask/issues/444
var property = new AsyncReactiveProperty<int>(0);
var cts1 = new CancellationTokenSource();
var cts2 = new CancellationTokenSource();
WaitForProperty(property, cts1.Token);
WaitForProperty(property, cts2.Token);
_callCounter = 0;
property.Value = 1;
_callCounter.Should().Be(2);
cts2.Cancel();
cts2.Dispose();
cts1.Cancel();
cts1.Dispose();
var cts3 = new CancellationTokenSource();
WaitForProperty(property, cts3.Token);
_callCounter = 0;
property.Value = 2;
_callCounter.Should().Be(1);
cts3.Cancel();
cts3.Dispose();
await UniTask.CompletedTask;
});
private async void WaitForProperty(AsyncReactiveProperty<int> property, CancellationToken token)
{
while (true)
{
try
{
await property.WaitAsync(token);
_callCounter++;
}
catch (OperationCanceledException)
{
break;
}
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 27665955eefb4448969b8cc4dd204600
timeCreated: 1676129650