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
2 changed files with 14 additions and 16 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

@ -42,7 +42,6 @@ namespace Cysharp.Threading.Tasks
while (h != null)
{
iteratingNode = h;
var next = h.Next;
try
{
@ -54,7 +53,9 @@ namespace Cysharp.Threading.Tasks
Remove(h);
}
h = next;
// If `h` itself is removed by OnNext, h.Next is null.
// Therefore, instead of looking at h.Next, the `iteratingNode` reference itself is replaced.
h = h == iteratingNode ? h.Next : iteratingNode;
}
iteratingNode = null;
@ -238,18 +239,20 @@ namespace Cysharp.Threading.Tasks
{
head = next;
}
else if (handler == iteratingHead)
// when handler is head, prev indicate last so don't use it.
else if (prev != null)
{
prev.Next = next;
}
if (handler == iteratingNode)
{
iteratingNode = next;
}
if (handler == iteratingHead)
{
iteratingHead = next;
}
else
{
// when handler is head, prev indicate last so don't use it.
if (prev != null)
{
prev.Next = next;
}
}
if (head != null)
{