Skip to content

Commit

Permalink
Don't reuse a ValueTask
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Jan 8, 2025
1 parent c96ac50 commit a73c2c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ internal static TValueTask FallbackResultActivator(TResult task)
=> (TValueTask)Activator.CreateInstance(typeof(TValueTask), task)!;

public static TValueTask CreateInstance(Task<TResult> task) => TaskActivator(task);

public static TValueTask CreateInstance(TResult result) => ResultActivator(result);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public SyncCallbackHandler(ContinuationMethodDelegate continuation, bool preserv
// ok all good, just run synchronously
var unwrappedResult = previousValueTask.Result;
_continuation(instance, unwrappedResult, exception, in state);
return returnValue;
return ValueTaskActivator<TReturn, TResult?>.CreateInstance(unwrappedResult);
}

// uh oh, need to extract the task, await it, run the continuation
Expand Down

0 comments on commit a73c2c7

Please sign in to comment.