Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return type issues in "SignalR API design considerations" #32492

Merged
merged 1 commit into from May 2, 2024

Conversation

JonathanBout
Copy link
Contributor

@JonathanBout JonathanBout commented May 1, 2024

Page: https://learn.microsoft.com/en-us/aspnet/core/signalr/api-design?view=aspnetcore-8.0

  • A lot of functions were async and returned Task without awaiting anything which is
  • Some functions had a 'void' Task as return type but actually returned a value
  • Some functions returned string while that should be int

EDIT by @Rick-Anderson
Fixes #32505

- A lot of functions were async and returned `Task` without awaiting anything
- Some functions had a void Task as return type but actually returned a value
@Rick-Anderson
Copy link
Contributor

SignalR code is asynchronous to provide maximum scalability. I think it would be better to await.

@BrennanConroy
Copy link
Member

There is nothing to await in the code being changed. This looks fine.

@BrennanConroy
Copy link
Member

  • Some functions had a 'void' Task as return type but actually returned a value

Where?

@Rick-Anderson
Copy link
Contributor

Why not:

public async Task<string> GetTotalLengthAsync(string param1)
{
    // GetStringAsync is an async method that returns Task<string>
    string result = await GetStringAsync(param1);
    return result.Length.ToString();
}

@BrennanConroy
Copy link
Member

Because that's just adding a new function without any reason. Returning a quick result synchronously is fine. If we are lacking docs that show results being returned asynchronously then that should be a different change.

@Rick-Anderson Rick-Anderson merged commit d943b22 into dotnet:main May 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when to use async in SignalR code
3 participants