This is maybe a trivial question but currently im doing some Inline-Documentation for future Coworkers and stumbled upon something like that:
/// <summary> /// This Class is totaly useless /// </summary> public class DummyClass { /// <summary> /// Will do nothing /// </summary> public void DoNothing() { } /// <summary> /// Will do nothing async /// </summary> /// <returns></returns> <---- What to write here? public async Task DoNothingAsync() { await Task.Run(() => { }); } }
As you might know, typing 3 slashes above an Method/Field/Class/whatever, triggers VisualStudio to perform its Summary-Snippet-Completion.
Question
Is Task
actually a valid return-value? And if so, what do i write in the <returns></returns>
?
I surely do know, i can ignore this, but for the sake of completeness im willing to write stuff there.
In short, if your async method is an event handler or a callback, it's ok to return void .
Async functions always return a promise. If the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. Note: Even though the return value of an async function behaves as if it's wrapped in a Promise.resolve , they are not equivalent.
async void has the same semantics as async Task , except for exceptions. An async void method will capture the current SynchronizationContext at the beginning of the method, and any exceptions from that method will be captured and raised directly on that captured context.
The async void case is a “fire and forget”: You start the task chain, but you don't care about when it's finished. When the function returns, all you know is that everything up to the first await has executed. Everything after the first await will run at some unspecified point in the future that you have no access to.
If we take inspiration from API's that Microsoft have produced recently, you might just state:
<returns>No object or value is returned by this method when it completes.</returns>
I dislike "A task object that can be awaited" for the same reason I wouldn't decorate a method that returns an int
with "an integer which can be compared to zero or used in mathematical operations" - it doesn't describe the return value of the method, it describes the type. The type has its own documentation which can be consulted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With