-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add missing "await" prefix or "Async" suffix in "async" methods #6787
base: master
Are you sure you want to change the base?
Conversation
2c8c411
to
3d3f554
Compare
@@ -59,7 +59,7 @@ public static IMemoryOwner<byte> StreamToRentedMemory(Stream input) | |||
|
|||
public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default) | |||
{ | |||
using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); | |||
await using MemoryStream stream = MemoryStreamManager.Shared.GetStream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no point in async-disposing of a MemoryStream, it just adds overhead around calling Dispose().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -479,7 +479,7 @@ private async Task UpdateAmiiboPreview(string imageUrl) | |||
if (response.IsSuccessStatusCode) | |||
{ | |||
byte[] amiiboPreviewBytes = await response.Content.ReadAsByteArrayAsync(); | |||
using MemoryStream memoryStream = new(amiiboPreviewBytes); | |||
await using MemoryStream memoryStream = new(amiiboPreviewBytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted elsewhere, async-disposing a MemoryStream
only adds overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -97,7 +97,7 @@ public static string ReadAllText(Assembly assembly, string filename) | |||
|
|||
public async static Task<string> ReadAllTextAsync(Assembly assembly, string filename) | |||
{ | |||
using var stream = GetStream(assembly, filename); | |||
await using var stream = GetStream(assembly, filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These Stream
s returned by GetStream()
-> Assembly.GetManifestResourceStream()
are based on UnmanagedMemoryStream
, and disposing asynchronously only adds overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
No description provided.