Replies: 2 comments 8 replies
-
This feels like more of an abuse of Task<TResult> RunAsTask<TResult>(Func<TResult> func)
{
try { return Task.FromResult(func()); }
catch (Exception e) { return Task.FromException<TResult>(e); }
}
public static Task<int> Test1(bool err) => RunAsTask(() =>
{
if (err)
throw new InvalidOperationException();
return GetNum(42);
}); |
Beta Was this translation helpful? Give feedback.
4 replies
-
Or just keep the method async and suppress the warning |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Inspired from this: https://stackoverflow.com/questions/64062682/warning-cs1998-this-async-method-lacks-await-operator-correct-way-to-silence
Several incorrect ways to fix CS1998 and at same time change problem flow.
As I see it, the only way to fix CS1998 without changing program flow is to do:
from
to
It is easy, but I think I have never seen this been done correctly. So I suggest a new keyword "sync" that will create this logic automatically, just like a state machine is created from async.
Like this:
Beta Was this translation helpful? Give feedback.
All reactions