Skip to content

Commit

Permalink
Release handle when cancellation is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianoPC committed Nov 22, 2023
1 parent 5cc97c7 commit 36ac086
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

namespace Cysharp.Threading.Tasks
Expand Down Expand Up @@ -171,6 +172,10 @@ void Continuation(AsyncOperationHandle _)
completed = true;
if (cancellationToken.IsCancellationRequested)
{
If (handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
}
else if (handle.Status == AsyncOperationStatus.Failed)
Expand Down Expand Up @@ -215,6 +220,10 @@ public bool MoveNext()
if (cancellationToken.IsCancellationRequested)
{
completed = true;
if (handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
return false;
}
Expand Down Expand Up @@ -353,6 +362,10 @@ void Continuation(AsyncOperationHandle<T> argHandle)
completed = true;
if (cancellationToken.IsCancellationRequested)
{
if (handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
}
else if (argHandle.Status == AsyncOperationStatus.Failed)
Expand Down Expand Up @@ -402,6 +415,10 @@ public bool MoveNext()
if (cancellationToken.IsCancellationRequested)
{
completed = true;
if (handle.IsValid())
{
Addressables.Release(handle);
}
core.TrySetCanceled(cancellationToken);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "UniTask.Addressables",
"references": [
"UniTask",
"Unity.ResourceManager"
"Unity.ResourceManager",
"Unity.Addressables"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down

0 comments on commit 36ac086

Please sign in to comment.