From 4d204e4aa6632b0a913f572a87177a3efbe71c59 Mon Sep 17 00:00:00 2001 From: Yoshifumi Kawai <46207+neuecc@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:49:34 +0900 Subject: [PATCH 01/11] Update build-debug.yml --- .github/workflows/build-debug.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-debug.yml b/.github/workflows/build-debug.yml index 5c069f6..e3bd6a6 100644 --- a/.github/workflows/build-debug.yml +++ b/.github/workflows/build-debug.yml @@ -81,6 +81,7 @@ jobs: # Store artifacts. - uses: Cysharp/Actions/.github/actions/upload-artifact@main + if: ${{ startsWith(matrix.unity, '2021') }} # only execute 2021 with: name: UniTask.unitypackage-${{ matrix.unity }}.zip path: ./src/UniTask/*.unitypackage From 83d8a2b424a2ee7137f8671770e9acb2b9d325f0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:20:07 +0000 Subject: [PATCH 02/11] feat: Update package.json to 2.5.6 --- src/UniTask/Assets/Plugins/UniTask/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/package.json b/src/UniTask/Assets/Plugins/UniTask/package.json index 65f7a13..c71272f 100644 --- a/src/UniTask/Assets/Plugins/UniTask/package.json +++ b/src/UniTask/Assets/Plugins/UniTask/package.json @@ -2,7 +2,7 @@ "name": "com.cysharp.unitask", "displayName": "UniTask", "author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" }, - "version": "2.5.5", + "version": "2.5.6", "unity": "2018.4", "description": "Provides an efficient async/await integration to Unity.", "keywords": [ "async/await", "async", "Task", "UniTask" ], From dfe5ee43c201bef278be5bd59185756a7750c34a Mon Sep 17 00:00:00 2001 From: Kochoyume <78918084+kochounoyume@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:37:44 +0900 Subject: [PATCH 03/11] Add overload in UniTask.WaitUntil, UniTask.WaitWhile and UniTask.Defer to avoid closure allocation --- .../UniTask/Runtime/UniTask.Factory.cs | 103 +++++++ .../UniTask/Runtime/UniTask.WaitUntil.cs | 265 +++++++++++++++++- src/UniTask/Assets/Tests/AsyncTest.cs | 33 +++ 3 files changed, 398 insertions(+), 3 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index bd66aba..8d4f0c5 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -202,6 +202,22 @@ namespace Cysharp.Threading.Tasks return new UniTask(new DeferPromise(factory), 0); } + /// + /// Defer the task creation just before call await. + /// + public static UniTask Defer(TState state, Func factory) + { + return new UniTask(new DeferPromiseWithState(state, factory), 0); + } + + /// + /// Defer the task creation just before call await. + /// + public static UniTask Defer(TState state, Func> factory) + { + return new UniTask(new DeferPromiseWithState(state, factory), 0); + } + /// /// Never complete. /// @@ -465,6 +481,93 @@ namespace Cysharp.Threading.Tasks } } + sealed class DeferPromiseWithState : IUniTaskSource + { + Func factory; + TState argument; + UniTask task; + UniTask.Awaiter awaiter; + + public DeferPromiseWithState(TState argument, Func factory) + { + this.argument = argument; + this.factory = factory; + } + + public void GetResult(short token) + { + awaiter.GetResult(); + } + + public UniTaskStatus GetStatus(short token) + { + var f = Interlocked.Exchange(ref factory, null); + if (f != null) + { + task = f(argument); + awaiter = task.GetAwaiter(); + } + + return task.Status; + } + + public void OnCompleted(Action continuation, object state, short token) + { + awaiter.SourceOnCompleted(continuation, state); + } + + public UniTaskStatus UnsafeGetStatus() + { + return task.Status; + } + } + + sealed class DeferPromiseWithState : IUniTaskSource + { + Func> factory; + TState argument; + UniTask task; + UniTask.Awaiter awaiter; + + public DeferPromiseWithState(TState argument, Func> factory) + { + this.argument = argument; + this.factory = factory; + } + + public TResult GetResult(short token) + { + return awaiter.GetResult(); + } + + void IUniTaskSource.GetResult(short token) + { + awaiter.GetResult(); + } + + public UniTaskStatus GetStatus(short token) + { + var f = Interlocked.Exchange(ref factory, null); + if (f != null) + { + task = f(argument); + awaiter = task.GetAwaiter(); + } + + return task.Status; + } + + public void OnCompleted(Action continuation, object state, short token) + { + awaiter.SourceOnCompleted(continuation, state); + } + + public UniTaskStatus UnsafeGetStatus() + { + return task.Status; + } + } + sealed class NeverPromise : IUniTaskSource { static readonly Action cancellationCallback = CancellationCallback; diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs index c5e5915..2f29b64 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs @@ -15,11 +15,21 @@ namespace Cysharp.Threading.Tasks return new UniTask(WaitUntilPromise.Create(predicate, timing, cancellationToken, cancelImmediately, out var token), token); } + public static UniTask WaitUntil(T state, Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + { + return new UniTask(WaitUntilPromise.Create(state, predicate, timing, cancellationToken, cancelImmediately, out var token), token); + } + public static UniTask WaitWhile(Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) { return new UniTask(WaitWhilePromise.Create(predicate, timing, cancellationToken, cancelImmediately, out var token), token); } + public static UniTask WaitWhile(T state, Func predicate, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false) + { + return new UniTask(WaitWhilePromise.Create(state, predicate, timing, cancellationToken, cancelImmediately, out var token), token); + } + public static UniTask WaitUntilCanceled(CancellationToken cancellationToken, PlayerLoopTiming timing = PlayerLoopTiming.Update, bool completeImmediately = false) { return new UniTask(WaitUntilCanceledPromise.Create(cancellationToken, timing, completeImmediately, out var token), token); @@ -162,6 +172,131 @@ namespace Cysharp.Threading.Tasks } } + sealed class WaitUntilPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> + { + static TaskPool> pool; + WaitUntilPromise nextNode; + public ref WaitUntilPromise NextNode => ref nextNode; + + static WaitUntilPromise() + { + TaskPool.RegisterSizeGetter(typeof(WaitUntilPromise), () => pool.Size); + } + + Func predicate; + T argument; + CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; + + UniTaskCompletionSourceCore core; + + WaitUntilPromise() + { + } + + public static IUniTaskSource Create(T argument, Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + if (!pool.TryPop(out var result)) + { + result = new WaitUntilPromise(); + } + + result.predicate = predicate; + result.argument = argument; + result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitUntilPromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + + TaskTracker.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + core.GetResult(token); + } + finally + { + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } + } + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + return false; + } + + try + { + if (!predicate(argument)) + { + return true; + } + } + catch (Exception ex) + { + core.TrySetException(ex); + return false; + } + + core.TrySetResult(null); + return false; + } + + bool TryReturn() + { + TaskTracker.RemoveTracking(this); + core.Reset(); + predicate = default; + argument = default; + cancellationToken = default; + cancellationTokenRegistration.Dispose(); + cancelImmediately = default; + return pool.TryPush(this); + } + } + sealed class WaitWhilePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; @@ -199,7 +334,7 @@ namespace Cysharp.Threading.Tasks result.predicate = predicate; result.cancellationToken = cancellationToken; result.cancelImmediately = cancelImmediately; - + if (cancelImmediately && cancellationToken.CanBeCanceled) { result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => @@ -288,6 +423,130 @@ namespace Cysharp.Threading.Tasks } } + sealed class WaitWhilePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> + { + static TaskPool> pool; + WaitWhilePromise nextNode; + public ref WaitWhilePromise NextNode => ref nextNode; + + static WaitWhilePromise() + { + TaskPool.RegisterSizeGetter(typeof(WaitWhilePromise), () => pool.Size); + } + + Func predicate; + T argument; + CancellationToken cancellationToken; + CancellationTokenRegistration cancellationTokenRegistration; + bool cancelImmediately; + + UniTaskCompletionSourceCore core; + + WaitWhilePromise() + { + } + + public static IUniTaskSource Create(T argument, Func predicate, PlayerLoopTiming timing, CancellationToken cancellationToken, bool cancelImmediately, out short token) + { + if (cancellationToken.IsCancellationRequested) + { + return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token); + } + + if (!pool.TryPop(out var result)) + { + result = new WaitWhilePromise(); + } + + result.predicate = predicate; + result.argument = argument; + result.cancellationToken = cancellationToken; + + if (cancelImmediately && cancellationToken.CanBeCanceled) + { + result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => + { + var promise = (WaitWhilePromise)state; + promise.core.TrySetCanceled(promise.cancellationToken); + }, result); + } + + TaskTracker.TrackActiveTask(result, 3); + + PlayerLoopHelper.AddAction(timing, result); + + token = result.core.Version; + return result; + } + + public void GetResult(short token) + { + try + { + core.GetResult(token); + } + finally + { + if (!(cancelImmediately && cancellationToken.IsCancellationRequested)) + { + TryReturn(); + } + } + } + + public UniTaskStatus GetStatus(short token) + { + return core.GetStatus(token); + } + + public UniTaskStatus UnsafeGetStatus() + { + return core.UnsafeGetStatus(); + } + + public void OnCompleted(Action continuation, object state, short token) + { + core.OnCompleted(continuation, state, token); + } + + public bool MoveNext() + { + if (cancellationToken.IsCancellationRequested) + { + core.TrySetCanceled(cancellationToken); + return false; + } + + try + { + if (predicate(argument)) + { + return true; + } + } + catch (Exception ex) + { + core.TrySetException(ex); + return false; + } + + core.TrySetResult(null); + return false; + } + + bool TryReturn() + { + TaskTracker.RemoveTracking(this); + core.Reset(); + predicate = default; + argument = default; + cancellationToken = default; + cancellationTokenRegistration.Dispose(); + cancelImmediately = default; + return pool.TryPush(this); + } + } + sealed class WaitUntilCanceledPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; @@ -443,7 +702,7 @@ namespace Cysharp.Threading.Tasks result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; result.cancelImmediately = cancelImmediately; - + if (cancelImmediately && cancellationToken.CanBeCanceled) { result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => @@ -586,7 +845,7 @@ namespace Cysharp.Threading.Tasks result.equalityComparer = equalityComparer ?? UnityEqualityComparer.GetDefault(); result.cancellationToken = cancellationToken; result.cancelImmediately = cancelImmediately; - + if (cancelImmediately && cancellationToken.CanBeCanceled) { result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state => diff --git a/src/UniTask/Assets/Tests/AsyncTest.cs b/src/UniTask/Assets/Tests/AsyncTest.cs index 3cd98a3..29645da 100644 --- a/src/UniTask/Assets/Tests/AsyncTest.cs +++ b/src/UniTask/Assets/Tests/AsyncTest.cs @@ -145,6 +145,11 @@ namespace Cysharp.Threading.TasksTests public int MyProperty { get; set; } } + class MyBoolenClass + { + public bool MyProperty { get; set; } + } + [UnityTest] public IEnumerator WaitUntil() => UniTask.ToCoroutine(async () => { @@ -159,6 +164,20 @@ namespace Cysharp.Threading.TasksTests diff.Should().Be(11); }); + [UnityTest] + public IEnumerator WaitUntilWithState() => UniTask.ToCoroutine(async () => + { + var v = new MyBoolenClass { MyProperty = false }; + + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = true).Forget(); + + var startFrame = Time.frameCount; + await UniTask.WaitUntil(v, static v => v.MyProperty, PlayerLoopTiming.EarlyUpdate); + + var diff = Time.frameCount - startFrame; + diff.Should().Be(11); + }); + [UnityTest] public IEnumerator WaitWhile() => UniTask.ToCoroutine(async () => { @@ -173,6 +192,20 @@ namespace Cysharp.Threading.TasksTests diff.Should().Be(11); }); + [UnityTest] + public IEnumerator WaitWhileWithState() => UniTask.ToCoroutine(async () => + { + var v = new MyBoolenClass { MyProperty = true }; + + UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = false).Forget(); + + var startFrame = Time.frameCount; + await UniTask.WaitWhile(v, static v => v.MyProperty, PlayerLoopTiming.EarlyUpdate); + + var diff = Time.frameCount - startFrame; + diff.Should().Be(11); + }); + [UnityTest] public IEnumerator WaitUntilValueChanged() => UniTask.ToCoroutine(async () => { From 06283f0ffb0d9531815dadf049ac3578d4430e97 Mon Sep 17 00:00:00 2001 From: Kochoyume <78918084+kochounoyume@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:58:28 +0900 Subject: [PATCH 04/11] Add to the code that I forgot to write --- .../Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs index 2f29b64..b113353 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs @@ -241,6 +241,10 @@ namespace Cysharp.Threading.Tasks { TryReturn(); } + else + { + TaskTracker.RemoveTracking(this); + } } } @@ -461,6 +465,7 @@ namespace Cysharp.Threading.Tasks result.predicate = predicate; result.argument = argument; result.cancellationToken = cancellationToken; + result.cancelImmediately = cancelImmediately; if (cancelImmediately && cancellationToken.CanBeCanceled) { @@ -491,6 +496,10 @@ namespace Cysharp.Threading.Tasks { TryReturn(); } + else + { + TaskTracker.RemoveTracking(this); + } } } From 74bbe87b58a727021ab0d6593b4b4816d26f307c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 06:24:48 +0000 Subject: [PATCH 05/11] feat: Update package.json to 2.5.7 --- src/UniTask/Assets/Plugins/UniTask/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/package.json b/src/UniTask/Assets/Plugins/UniTask/package.json index c71272f..0408504 100644 --- a/src/UniTask/Assets/Plugins/UniTask/package.json +++ b/src/UniTask/Assets/Plugins/UniTask/package.json @@ -2,7 +2,7 @@ "name": "com.cysharp.unitask", "displayName": "UniTask", "author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" }, - "version": "2.5.6", + "version": "2.5.7", "unity": "2018.4", "description": "Provides an efficient async/await integration to Unity.", "keywords": [ "async/await", "async", "Task", "UniTask" ], From 0b16005f4becb47c2ca06a6c8e2db976c93e1a23 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 26 Sep 2024 22:33:37 +0200 Subject: [PATCH 06/11] Added a note for users using Unity 2023.1 or newer --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c6eb446..277c0c6 100644 --- a/README.md +++ b/README.md @@ -526,6 +526,9 @@ It indicates when to run, you can check [PlayerLoopList.md](https://gist.github. In UniTask, await directly uses native timing, while `WithCancellation` and `ToUniTask` use specified timing. This is usually not a particular problem, but with `LoadSceneAsync`, it causes a different order of Start and continuation after await. So it is recommended not to use `LoadSceneAsync.ToUniTask`. +> Note: When using Unity 2023.1 or newer, ensure you have `using UnityEngine;` in the using statements of your file when working with new `UnityEngine.Awaitable` methods like `SceneManager.LoadSceneAsync`. +> This prevents compilation errors by avoiding the use of the `UnityEngine.AsyncOperation` version. + In the stacktrace, you can check where it is running in playerloop. ![image](https://user-images.githubusercontent.com/46207/83735571-83caea80-a68b-11ea-8d22-5e22864f0d24.png) From fdb9d1cf95a1337983c94b133e49028169b44138 Mon Sep 17 00:00:00 2001 From: dvsilch <64416955+dvsilch@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:57:05 +0800 Subject: [PATCH 07/11] feature: add overload in UniTask.UnityAction to support generic type UnityAction --- .../UniTask/Runtime/UniTask.Factory.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index 8d4f0c5..82d44fa 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -184,6 +184,42 @@ namespace Cysharp.Threading.Tasks return () => asyncAction(state).Forget(); } + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T state) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + { + return (state) => asyncAction(state); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 s1, T2 s2) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + { + return (s1, s2) => asyncAction(s1, s2); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 s1, T2 s2, T3 s3) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + { + return (s1, s2, s3) => asyncAction(s1, s2, s3); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 s1, T2 s2, T3 s3, T4 s4) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + { + return (s1, s2, s3, s4) => asyncAction(s1, s2, s3, s4); + } + #endif /// From cf19f18662191d4aadd6864f7ae037834815902d Mon Sep 17 00:00:00 2001 From: dvsilch <64416955+dvsilch@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:57:36 +0800 Subject: [PATCH 08/11] fix: typo --- src/UniTask/Assets/Tests/AsyncTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/UniTask/Assets/Tests/AsyncTest.cs b/src/UniTask/Assets/Tests/AsyncTest.cs index 29645da..2f07d1e 100644 --- a/src/UniTask/Assets/Tests/AsyncTest.cs +++ b/src/UniTask/Assets/Tests/AsyncTest.cs @@ -145,7 +145,7 @@ namespace Cysharp.Threading.TasksTests public int MyProperty { get; set; } } - class MyBoolenClass + class MyBooleanClass { public bool MyProperty { get; set; } } @@ -167,7 +167,7 @@ namespace Cysharp.Threading.TasksTests [UnityTest] public IEnumerator WaitUntilWithState() => UniTask.ToCoroutine(async () => { - var v = new MyBoolenClass { MyProperty = false }; + var v = new MyBooleanClass { MyProperty = false }; UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = true).Forget(); @@ -195,7 +195,7 @@ namespace Cysharp.Threading.TasksTests [UnityTest] public IEnumerator WaitWhileWithState() => UniTask.ToCoroutine(async () => { - var v = new MyBoolenClass { MyProperty = true }; + var v = new MyBooleanClass { MyProperty = true }; UniTask.DelayFrame(10, PlayerLoopTiming.PostLateUpdate).ContinueWith(() => v.MyProperty = false).Forget(); From 353f15e94fbad17c1ae5c4c7bc026674340c2bed Mon Sep 17 00:00:00 2001 From: dvsilch <64416955+dvsilch@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:43:16 +0800 Subject: [PATCH 09/11] fix: add .Forget() call and rename paramters to keep coding style consistent --- .../Plugins/UniTask/Runtime/UniTask.Factory.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index 82d44fa..e04949b 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -190,34 +190,34 @@ namespace Cysharp.Threading.Tasks /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (state) => asyncAction(state); + return (state) => asyncAction(state).Forget(); } /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 s1, T2 s2) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 state1, T2 state2) => { /* */ } )) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (s1, s2) => asyncAction(s1, s2); + return (state1, state2) => asyncAction(state1, state2).Forget(); } /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 s1, T2 s2, T3 s3) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 state1, T2 state2, T3 state3) => { /* */ } )) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (s1, s2, s3) => asyncAction(s1, s2, s3); + return (state1, state2, state3) => asyncAction(state1, state2, state3).Forget(); } /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 s1, T2 s2, T3 s3, T4 s4) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 state1, T2 state2, T3 state3, T4 state4) => { /* */ } )) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (s1, s2, s3, s4) => asyncAction(s1, s2, s3, s4); + return (state1, state2, state3, state4) => asyncAction(state1, state2, state3, state4).Forget(); } #endif From bf945a7ef4b4470278f9615343c7c848b22ff3f1 Mon Sep 17 00:00:00 2001 From: dvsilch <64416955+dvsilch@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:10:35 +0800 Subject: [PATCH 10/11] fix: rename parameters and type parameters --- .../UniTask/Runtime/UniTask.Factory.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index e04949b..1a0030f 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -186,38 +186,38 @@ namespace Cysharp.Threading.Tasks /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T state) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T arg) => { /* */ } )) /// public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (state) => asyncAction(state).Forget(); + return (arg) => asyncAction(arg).Forget(); } /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 state1, T2 state2) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T0 arg0, T1 arg1) => { /* */ } )) /// - public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (state1, state2) => asyncAction(state1, state2).Forget(); + return (arg0, arg1) => asyncAction(arg0, arg1).Forget(); } /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 state1, T2 state2, T3 state3) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T0 arg0, T1 arg1, T2 arg2) => { /* */ } )) /// - public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (state1, state2, state3) => asyncAction(state1, state2, state3).Forget(); + return (arg0, arg1, arg2) => asyncAction(arg0, arg1, arg2).Forget(); } /// /// Create async void(UniTaskVoid) UnityAction. - /// For example: onClick.AddListener(UniTask.UnityAction(async (T1 state1, T2 state2, T3 state3, T4 state4) => { /* */ } )) + /// For example: onClick.AddListener(UniTask.UnityAction(async (T0 arg0, T1 arg1, T2 arg2, T3 arg3) => { /* */ } )) /// - public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction) { - return (state1, state2, state3, state4) => asyncAction(state1, state2, state3, state4).Forget(); + return (arg0, arg1, arg2, arg3) => asyncAction(arg0, arg1, arg2, arg3).Forget(); } #endif From a51632cd4b2512e7f14e89e5ffcf91dd3bf742d8 Mon Sep 17 00:00:00 2001 From: dvsilch <64416955+dvsilch@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:13:29 +0800 Subject: [PATCH 11/11] fix: add overloads for CancellationToken --- .../UniTask/Runtime/UniTask.Factory.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs index 1a0030f..8bdec75 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs @@ -220,6 +220,42 @@ namespace Cysharp.Threading.Tasks return (arg0, arg1, arg2, arg3) => asyncAction(arg0, arg1, arg2, arg3).Forget(); } + // + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T arg, CancellationToken cancellationToken) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) + { + return (arg) => asyncAction(arg, cancellationToken).Forget(); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T0 arg0, T1 arg1, CancellationToken cancellationToken) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) + { + return (arg0, arg1) => asyncAction(arg0, arg1, cancellationToken).Forget(); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T0 arg0, T1 arg1, T2 arg2, CancellationToken cancellationToken) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) + { + return (arg0, arg1, arg2) => asyncAction(arg0, arg1, arg2, cancellationToken).Forget(); + } + + /// + /// Create async void(UniTaskVoid) UnityAction. + /// For example: onClick.AddListener(UniTask.UnityAction(async (T0 arg0, T1 arg1, T2 arg2, T3 arg3, CancellationToken cancellationToken) => { /* */ } )) + /// + public static UnityEngine.Events.UnityAction UnityAction(Func asyncAction, CancellationToken cancellationToken) + { + return (arg0, arg1, arg2, arg3) => asyncAction(arg0, arg1, arg2, arg3, cancellationToken).Forget(); + } + #endif ///