Merge pull request #220 from taigacon/master

Fix using AsyncUnityEventHandler with a already canceled token
master
Yoshifumi Kawai 2021-02-08 14:51:21 +09:00 committed by GitHub
commit 638522600a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -364,6 +364,7 @@ namespace Cysharp.Threading.Tasks
public AsyncUnityEventHandler(UnityEvent unityEvent, CancellationToken cancellationToken, bool callOnce)
{
this.cancellationToken = cancellationToken;
if (cancellationToken.IsCancellationRequested)
{
isDisposed = true;
@ -372,7 +373,6 @@ namespace Cysharp.Threading.Tasks
this.action = Invoke;
this.unityEvent = unityEvent;
this.cancellationToken = cancellationToken;
this.callOnce = callOnce;
unityEvent.AddListener(action);
@ -388,6 +388,10 @@ namespace Cysharp.Threading.Tasks
public UniTask OnInvokeAsync()
{
core.Reset();
if (isDisposed)
{
core.TrySetCanceled(this.cancellationToken);
}
return new UniTask(this, core.Version);
}
@ -470,6 +474,7 @@ namespace Cysharp.Threading.Tasks
public AsyncUnityEventHandler(UnityEvent<T> unityEvent, CancellationToken cancellationToken, bool callOnce)
{
this.cancellationToken = cancellationToken;
if (cancellationToken.IsCancellationRequested)
{
isDisposed = true;
@ -478,7 +483,6 @@ namespace Cysharp.Threading.Tasks
this.action = Invoke;
this.unityEvent = unityEvent;
this.cancellationToken = cancellationToken;
this.callOnce = callOnce;
unityEvent.AddListener(action);
@ -494,6 +498,10 @@ namespace Cysharp.Threading.Tasks
public UniTask<T> OnInvokeAsync()
{
core.Reset();
if (isDisposed)
{
core.TrySetCanceled(this.cancellationToken);
}
return new UniTask<T>(this, core.Version);
}