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 FluentAssertions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Channels;
using Cysharp.Threading.Tasks.Linq;
using System.Threading.Tasks;
using Xunit; using Xunit;
namespace NetCoreTests namespace NetCoreTests

View File

@ -42,7 +42,6 @@ namespace Cysharp.Threading.Tasks
while (h != null) while (h != null)
{ {
iteratingNode = h; iteratingNode = h;
var next = h.Next;
try try
{ {
@ -54,7 +53,9 @@ namespace Cysharp.Threading.Tasks
Remove(h); 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; iteratingNode = null;
@ -238,17 +239,19 @@ namespace Cysharp.Threading.Tasks
{ {
head = next; head = next;
} }
else if (handler == iteratingHead)
{
iteratingHead = next;
}
else
{
// when handler is head, prev indicate last so don't use it. // when handler is head, prev indicate last so don't use it.
if (prev != null) else if (prev != null)
{ {
prev.Next = next; prev.Next = next;
} }
if (handler == iteratingNode)
{
iteratingNode = next;
}
if (handler == iteratingHead)
{
iteratingHead = next;
} }
if (head != null) if (head != null)