mirror of https://github.com/Cysharp/UniTask
Compare commits
7 Commits
35f2fca99a
...
fe1d15b4a7
Author | SHA1 | Date |
---|---|---|
|
fe1d15b4a7 | |
|
4c3d6938ed | |
|
b4486802f2 | |
|
87c04a29fa | |
|
952e113011 | |
|
03ef341096 | |
|
5e266f5538 |
|
@ -159,6 +159,30 @@ namespace NetCoreTests.Linq
|
||||||
list.Should().Equal(100, 200, 300, 400);
|
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)
|
async IAsyncEnumerable<int> Range(int from, int count)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
|
|
|
@ -98,6 +98,23 @@ namespace Cysharp.Threading.Tasks
|
||||||
if (!tween.IsActive()) return UniTask.CompletedTask;
|
if (!tween.IsActive()) return UniTask.CompletedTask;
|
||||||
return new UniTask(TweenConfiguredSource.Create(tween, tweenCancelBehaviour, cancellationToken, CallbackType.StepComplete, out var token), token);
|
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
|
public struct TweenAwaiter : ICriticalNotifyCompletion
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
{
|
{
|
||||||
TaskTracker.RemoveTracking(this);
|
TaskTracker.RemoveTracking(this);
|
||||||
|
writer.Dispose();
|
||||||
return default;
|
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;
|
readonly _Create enumerator;
|
||||||
|
|
||||||
|
@ -137,6 +138,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||||
{
|
{
|
||||||
this.enumerator = enumerator;
|
this.enumerator = enumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
var status = core.GetStatus(core.Version);
|
||||||
|
if (status == UniTaskStatus.Pending)
|
||||||
|
{
|
||||||
|
core.TrySetCanceled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void GetResult(short token)
|
public void GetResult(short token)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue