I hope this is not a repetition, but there are 5000 more questions in which "not all code paths return a value"!
Simply put, why this non-standard implementation method compiles just fine:
public static async Task TimeoutAfter(this Task task, int millisecondsTimeout) { if (task == await Task.WhenAny(task, Task.Delay(millisecondsTimeout))) await task; else throw new TimeoutException(); }
while this attempt to make a generic method generates a warning Return state missing / ... not all code paths return a value :
public static async Task<T> TimeoutAfter<T>(this Task<T> task, int millisecondsTimeout) { if (task == await Task.WhenAny(task, Task.Delay(millisecondsTimeout))) await task; else throw new TimeoutException(); }
source share