Change AsyncEnumerable factory to use OperationCanceledException
parent
94be2e748b
commit
2cf06af433
|
@ -56,10 +56,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
|
||||
|
||||
if (disposed) return CompletedTasks.False;
|
||||
|
||||
completionSource.Reset();
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
|
@ -76,7 +80,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested)
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (disposed)
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
return false;
|
||||
|
|
|
@ -85,8 +85,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
|
||||
if (disposed) return CompletedTasks.False;
|
||||
|
||||
completionSource.Reset();
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
if (first)
|
||||
{
|
||||
|
@ -99,7 +106,6 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
return CompletedTasks.True;
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
|
@ -107,6 +113,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
{
|
||||
if (!disposed)
|
||||
{
|
||||
cancellationTokenRegistration.Dispose();
|
||||
disposed = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
}
|
||||
|
@ -115,13 +122,18 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested || targetAsUnityObject == null) // destroyed = cancel.
|
||||
if (disposed || targetAsUnityObject == null)
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
DisposeAsync().Forget();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
TProperty nextValue = default(TProperty);
|
||||
try
|
||||
{
|
||||
|
@ -205,8 +217,16 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested) return CompletedTasks.False;
|
||||
if (disposed) return CompletedTasks.False;
|
||||
|
||||
completionSource.Reset();
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
|
@ -218,7 +238,6 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
return CompletedTasks.True;
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
|
@ -235,13 +254,19 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested || !target.TryGetTarget(out var t))
|
||||
if (disposed || !target.TryGetTarget(out var t))
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
DisposeAsync().Forget();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
TProperty nextValue = default(TProperty);
|
||||
try
|
||||
{
|
||||
|
|
|
@ -109,7 +109,6 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
this.ignoreTimeScale = ignoreTimeScale;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
|
||||
if (cancelImmediately && cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
|
||||
|
@ -128,12 +127,16 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested || completed) return CompletedTasks.False;
|
||||
if (disposed || completed) return CompletedTasks.False;
|
||||
|
||||
// reset value here.
|
||||
this.elapsed = 0;
|
||||
|
||||
completionSource.Reset();
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
|
@ -150,11 +153,16 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested)
|
||||
if (disposed)
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
return false;
|
||||
}
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dueTimePhase)
|
||||
{
|
||||
|
@ -261,13 +269,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// return false instead of throw
|
||||
if (disposed || cancellationToken.IsCancellationRequested || completed) return CompletedTasks.False;
|
||||
if (disposed || completed) return CompletedTasks.False;
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
|
||||
// reset value here.
|
||||
this.currentFrame = 0;
|
||||
|
||||
completionSource.Reset();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
@ -285,7 +295,12 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (disposed || cancellationToken.IsCancellationRequested)
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
return false;
|
||||
}
|
||||
if (disposed)
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue