You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Switch to ValueTask<T> to avoid allocations from commands
When commands complete before a method returning, we can avoid a Task allocation altogether by using ValueTask instead of Task. Since the goal of executing a command is typically to retrieve a value and use that right-away, the optimization makes sense in general.
Aligns with the new NotifyAsync for events too.
Fixes#125
/// Provides the <see cref="Forget"/> extension method to <see cref="ValueTask"/>.
8
+
/// </summary>
9
+
[EditorBrowsable(EditorBrowsableState.Never)]
10
+
publicstaticclassValueTaskExtensions
11
+
{
12
+
/// <summary>
13
+
/// Observes the value task to avoid exceptions.
14
+
/// </summary>
15
+
publicstaticvoidForget(thisValueTasktask)
16
+
{
17
+
// note: this code is inspired by a tweet from Ben Adams: https://twitter.com/ben_a_adams/status/1045060828700037125
18
+
// Only care about tasks that may fault (not completed) or are faulted,
19
+
// so fast-path for SuccessfullyCompleted and Canceled tasks.
20
+
if(!task.IsCompleted||task.IsFaulted)
21
+
{
22
+
// use "_" (Discard operation) to remove the warning IDE0058: Because this call is not awaited, execution of the current method continues before the call is completed
0 commit comments