From 887db5b281cc797313eed1b7dae7ff14df224d4e Mon Sep 17 00:00:00 2001 From: neuecc Date: Sat, 4 Jul 2020 06:36:14 +0900 Subject: [PATCH] 2.0.24 --- README.md | 34 ++++++++++++++++++- .../Assets/Plugins/UniTask/package.json | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a583978..95a859e 100644 --- a/README.md +++ b/README.md @@ -532,6 +532,38 @@ SelectAwaitWithCancellation(Func> selector) If you want to use the `async` method inside the func, use the `***Await` or `***AwaitWithCancellation`. +How to create async iterator, C# 8.0 supports async iterator(`async yield return`) but it only allows `IAsyncEnumerable` and of course requires C# 8.0. UniTask supports `UniTaskAsyncEnumerable.Create` method to create custom async iterator. + +```csharp +// IAsyncEnumerable, C# 8.0 version of async iterator. ( do not use this style, IAsyncEnumerable is not controled in UniTask). +public async IAsyncEnumerable MyEveryUpdate([EnumeratorCancellation]CancellationToken cancelationToken) +{ + var frameCount = 0; + await UniTask.Yield(); + while (!token.IsCancellationRequested) + { + yield return frameCount++; + await UniTask.Yield(); + } +} + +// UniTaskAsyncEnumerable.Create and use `await writer.YieldAsync` instead of `yield return`. +public IUniTaskAsyncEnumerable MyEveryUpdate() +{ + // writer(IAsyncWriter) has `YieldAsync(value)` method. + return UniTaskAsyncEnumerable.Create(async (writer, token) => + { + var frameCount = 0; + await UniTask.Yield(); + while (!token.IsCancellationRequested) + { + await writer.YieldAsync(frameCount++); // instead of `yield return` + await UniTask.Yield(); + } + }); +} +``` + Awaitable Events --- All uGUI component implements `***AsAsyncEnumerable` to convert asynchronous streams of events. @@ -812,7 +844,7 @@ After Unity 2019.3.4f1, Unity 2020.1a21, that support path query parameter of gi or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"` to `Packages/manifest.json`. -If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.23`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.23`. +If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.24`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.24`. ### Install via OpenUPM diff --git a/src/UniTask/Assets/Plugins/UniTask/package.json b/src/UniTask/Assets/Plugins/UniTask/package.json index 3c52fff..3f4d694 100644 --- a/src/UniTask/Assets/Plugins/UniTask/package.json +++ b/src/UniTask/Assets/Plugins/UniTask/package.json @@ -1,7 +1,7 @@ { "name": "com.cysharp.unitask", "displayName": "UniTask", - "version": "2.0.23", + "version": "2.0.24", "unity": "2018.4", "description": "Provides an efficient async/await integration to Unity.", "keywords": [ "async/await", "async", "Task", "UniTask" ],