Repository navigation
Conversation
Added AsUniTask test cases for completed tasks (successful + faulted)
Added AsUniTask test cases for canceled tasks
Added regression test cases to make sure pending tasks are in the correct state before & after await, and carries the expected result. These tests should also pass without my changes, I noticed there were no test cases for these methods.
|
Wouldn't it be much simpler to just await it? public static async UniTask<T> AsUniTask<T>(this Task<T> task, bool useCurrentSynchronizationContext = true)
=> await task.ConfigureAwait(useCurrentSynchronizationContext); |
Author
|
@timcassell
This test passes on [Fact]
public async Task AsUniTask_PendingTaskWithResult_CanBeAwaitedTwice()
{
var source = new TaskCompletionSource<int>();
UniTask<int> task = source.Task.AsUniTask();
source.SetResult(42);
Assert.Equal(42, await task);
Assert.Equal(42, await task);
}It's also worth noting that the README states "UniTask can not await twice" and doing so is generally unsupported anyway. Still, existing code that caches the result of I'm happy to switch to the |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #730
Both the generic and non-generic overloads for the
AsUniTaskmethod now have a switch ontask.Statusand returns a completedUniTaskif the inputtaskis in theCanceled,FaultedorRanToCompletionstate.Unit tests have been added for these already-completed cases. I also improved test coverage for some missing cases where a
Taskcompletes after theAsUniTaskcall. These tests pass both before and after my fix changes.Note that this is a behavioral change, a completed
Taskno longer forces a yield. This might cause problems if code leaned on the yield, but I believe this is now correct behavior.Thanks