Should I use async in the library?
It all depends. If you intend to use an asynchronous programming paradigm, then the answer is yes, the async and await keywords are needed most of the time. Most likely you will need to use async/await . This is due to the fact that in most situations it would be difficult to use only Task and Task<T> , since you will most likely have to reason about the results of the async operations that you invoke.
In addition, based on your question, it seems that you might have some confusion regarding the keywords themselves and their relation to the types Task and Task<T> . Let me clarify this for you.
The async allows you to use the await method. Best practice is to have all async methods return either Task or Task<T> if you cannot (for example, a button click event handler, as you showed above).
Methods that return Task or Task<T> represent asynchronous operations. When you are in the library, it is recommended that you use .ConfigureAwait(false) for the reasons described below here . In addition, I always point people to this detailed article on this subject.
To differentiate two approaches in your question:
The method below returns a Task<SignResponse> . This is an asynchronous operation that represents a login job. The method can be called by the caller to receive SignResponse .
private Task<SignResponse> GetSignDataAsync(SigningRequestType request) { return _service.SignAsync(request); }
Similarly, this version does the same ... except that the async/await keywords are not needed. The reason they are not needed is because the method itself does not need to use SignResponse , and therefore it can simply return Task<SignResponse> , as shown above. And, as you pointed out in your question, there really is a penalty if you use async/await keywords when they are not needed. In this case, an additional step of the finite state machine is added, since the result is obtained, as it was expected.
private async Task<SignResponse> GetSignDataAsync(SigningRequestType request) { return await _service.SignAsync(request).ConfigureAwait(false); }
Finally, if you needed to substantiate the answer, you can use the above keywords to do this as follows:
private async Task<SignResponse> GetSignDataAsync(SigningRequestType request) { var result = await _service.SignAsync(request).ConfigureAwait(false); if (result.SomeProperty == SomethingWeCareToCheck) { _log.Log("Wow, this was un-expected..."); } return result; }