Senior
Is it possible to declare an async method without await inside? Will such code compile?
sobes.tech AI
Answer from AI
Yes, in languages that support async/await (such as C# or JavaScript), you can declare a method as async without using await inside. Such code will compile and work.
However, the compiler usually issues a warning that an async method does not contain await, which may indicate that the method runs synchronously and async is unnecessary.
Example in C#:
public async Task<int> GetNumberAsync()
{
return 42; // No await
}
This method returns a completed Task<int>, but does not await anything asynchronously.
In QA Automation, this can be useful if the interface requires async, but the implementation is currently synchronous.