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

Revert "Fixed https://github.com/Cysharp/UniTask/issues/444" #488

Merged
merged 1 commit into from
Sep 1, 2023
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
109 changes: 66 additions & 43 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/TriggerEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public struct TriggerEvent<T>
{
ITriggerHandler<T> head; // head.prev is last
ITriggerHandler<T> iteratingHead;

bool preserveRemoveSelf;
ITriggerHandler<T> iteratingNode;

void LogError(Exception ex)
Expand All @@ -42,7 +44,6 @@ public void SetResult(T value)
while (h != null)
{
iteratingNode = h;
var next = h.Next;

try
{
Expand All @@ -54,7 +55,18 @@ public void SetResult(T value)
Remove(h);
}

h = next;
if (preserveRemoveSelf)
{
preserveRemoveSelf = false;
iteratingNode = null;
var next = h.Next;
Remove(h);
h = next;
}
else
{
h = h.Next;
}
}

iteratingNode = null;
Expand Down Expand Up @@ -84,7 +96,8 @@ public void SetCanceled(CancellationToken cancellationToken)
{
LogError(ex);
}


preserveRemoveSelf = false;
iteratingNode = null;
var next = h.Next;
Remove(h);
Expand Down Expand Up @@ -118,7 +131,8 @@ public void SetCompleted()
{
LogError(ex);
}


preserveRemoveSelf = false;
iteratingNode = null;
var next = h.Next;
Remove(h);
Expand Down Expand Up @@ -152,7 +166,8 @@ public void SetError(Exception exception)
{
LogError(ex);
}


preserveRemoveSelf = false;
iteratingNode = null;
var next = h.Next;
Remove(h);
Expand Down Expand Up @@ -225,64 +240,72 @@ public void Add(ITriggerHandler<T> handler)
public void Remove(ITriggerHandler<T> handler)
{
if (handler == null) throw new ArgumentNullException(nameof(handler));

var prev = handler.Prev;
var next = handler.Next;

if (next != null)
if (iteratingNode != null && iteratingNode == handler)
{
next.Prev = prev;
}

if (handler == head)
{
head = next;
}
else if (handler == iteratingHead)
{
iteratingHead = next;
// if remove self, reserve remove self after invoke completed.
preserveRemoveSelf = true;
}
else
{
// when handler is head, prev indicate last so don't use it.
if (prev != null)
var prev = handler.Prev;
var next = handler.Next;

if (next != null)
{
prev.Next = next;
next.Prev = prev;
}
}

if (head != null)
{
if (head.Prev == handler)
if (handler == head)
{
if (prev != head)
{
head.Prev = prev;
}
else
head = next;
}
else if (handler == iteratingHead)
{
iteratingHead = next;
}
else
{
// when handler is head, prev indicate last so don't use it.
if (prev != null)
{
head.Prev = null;
prev.Next = next;
}
}
}

if (iteratingHead != null)
{
if (iteratingHead.Prev == handler)
if (head != null)
{
if (prev != iteratingHead.Prev)
if (head.Prev == handler)
{
iteratingHead.Prev = prev;
if (prev != head)
{
head.Prev = prev;
}
else
{
head.Prev = null;
}
}
else
}

if (iteratingHead != null)
{
if (iteratingHead.Prev == handler)
{
iteratingHead.Prev = null;
if (prev != iteratingHead.Prev)
{
iteratingHead.Prev = prev;
}
else
{
iteratingHead.Prev = null;
}
}
}
}

handler.Prev = null;
handler.Next = null;
handler.Prev = null;
handler.Next = null;
}
}
}
}
63 changes: 0 additions & 63 deletions src/UniTask/Assets/Tests/AsyncReactivePropertyTest.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/UniTask/Assets/Tests/AsyncReactivePropertyTest.cs.meta

This file was deleted.

Loading