Compare commits

...

7 Commits

Author SHA1 Message Date
Origan fe1d15b4a7
Merge 87c04a29fa into 4c3d6938ed 2023-08-31 14:28:56 +03:00
hadashiA 4c3d6938ed
Merge pull request #484 from Cysharp/hadashiA/fix-async-enumerable
Fix problem with finally in UniTaskAsyncEnumerable.Create not being executed
2023-08-31 19:17:31 +09:00
hadashiA b4486802f2 Fix problem with part of await foreach not executing on break 2023-08-31 12:42:53 +09:00
Artem Ovchinnikov 87c04a29fa Formatting fixed 2023-01-11 17:20:15 +03:00
Artem Ovchinnikov 952e113011 Await added to prevent premature dispose 2023-01-11 17:17:07 +03:00
Artem Ovchinnikov 03ef341096 Fixed bug with OnKill delegate overriding 2023-01-08 11:40:11 +03:00
Artem Ovchinnikov 5e266f5538 Added new extension method
Added new extension method that fixes DoTween null-reference, when using GetCancellationOnDestroy()
2022-09-24 18:18:20 +03:00
3 changed files with 52 additions and 1 deletions

View File

@ -159,6 +159,30 @@ namespace NetCoreTests.Linq
list.Should().Equal(100, 200, 300, 400);
}
[Fact]
public async Task AwaitForeachBreak()
{
var finallyCalled = false;
var enumerable = UniTaskAsyncEnumerable.Create<int>(async (writer, _) =>
{
try
{
await writer.YieldAsync(1);
}
finally
{
finallyCalled = true;
}
});
await foreach (var x in enumerable)
{
x.Should().Be(1);
break;
}
finallyCalled.Should().BeTrue();
}
async IAsyncEnumerable<int> Range(int from, int count)
{
for (int i = 0; i < count; i++)

View File

@ -98,6 +98,23 @@ namespace Cysharp.Threading.Tasks
if (!tween.IsActive()) return UniTask.CompletedTask;
return new UniTask(TweenConfiguredSource.Create(tween, tweenCancelBehaviour, cancellationToken, CallbackType.StepComplete, out var token), token);
}
public static async UniTask AwaitWithCancellation(this Tween tween, CancellationToken cancellationToken)
{
Error.ThrowArgumentNullException(tween, nameof(tween));
if (!tween.IsActive()) await UniTask.CompletedTask;
using var registration = cancellationToken.Register(() =>
{
if (tween.IsActive())
{
tween.Kill();
}
});
await tween.ToUniTask(TweenCancelBehaviour.KillAndCancelAwait, cancellationToken);
}
public struct TweenAwaiter : ICriticalNotifyCompletion
{

View File

@ -52,6 +52,7 @@ namespace Cysharp.Threading.Tasks.Linq
public UniTask DisposeAsync()
{
TaskTracker.RemoveTracking(this);
writer.Dispose();
return default;
}
@ -127,7 +128,7 @@ namespace Cysharp.Threading.Tasks.Linq
}
}
sealed class AsyncWriter : IUniTaskSource, IAsyncWriter<T>
sealed class AsyncWriter : IUniTaskSource, IAsyncWriter<T>, IDisposable
{
readonly _Create enumerator;
@ -137,6 +138,15 @@ namespace Cysharp.Threading.Tasks.Linq
{
this.enumerator = enumerator;
}
public void Dispose()
{
var status = core.GetStatus(core.Version);
if (status == UniTaskStatus.Pending)
{
core.TrySetCanceled();
}
}
public void GetResult(short token)
{