Skip to content

Commit

Permalink
Merge pull request #488 from Cysharp/revert-445-fix-wait-async
Browse files Browse the repository at this point in the history
Revert "Fixed #444"
  • Loading branch information
hadashiA authored Sep 1, 2023
2 parents 548d56e + 29a1446 commit c1042b3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 109 deletions.
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.

0 comments on commit c1042b3

Please sign in to comment.