Skip to content

Commit

Permalink
fix async task
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbit0v0 committed Nov 1, 2023
1 parent 40b3da0 commit 347982e
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Http;

namespace Microsoft.Omex.Extensions.Hosting.Services.Web.Middlewares
Expand All @@ -19,18 +20,16 @@ private class UserEmail
public string Email { get; set; } = string.Empty;
}

public Task<(bool success, int bytesWritten)> TryWriteBytesAsync(HttpContext context, Memory<byte> memory)
public async Task<(bool success, int bytesWritten)> TryWriteBytesAsync(HttpContext context, Memory<byte> memory)
{
int bytesWritten = -1;
try{
context.Request.Body.Seek(0, SeekOrigin.Begin);
TextReader reader = new StreamReader(context.Request.Body);
UserEmail? email = await JsonSerializer.DeserializeAsync<UserEmail>(reader);
UserEmail? email;
using (TextReader reader = new StreamReader(context.Request.Body))
{
email = await JsonSerializer.DeserializeAsync<UserEmail>(reader);
}
UserEmail? email;
using (StreamReader reader = new(context.Request.Body)){
email = await JsonSerializer.DeserializeAsync<UserEmail>(reader.BaseStream);
}

bool success = email != null;
if (email != null)
{
Expand All @@ -42,11 +41,11 @@ private class UserEmail
}
}

return Task.FromResult((success, bytesWritten));
return (success, bytesWritten);
}

catch {
return Task.FromResult((false, -1));
return (false, -1);
}
}
}
Expand Down

0 comments on commit 347982e

Please sign in to comment.