Trying to do so involves using the weird syntax of GetAwaiter().GetResult()
.
Beside that fact, it works; but does it sucks to do so? If yes, then why?
Original:
internal static ISector Read(ISector sector, Stream stream)
{
using var scope = new ArrayPoolScope<byte>(GetLength(sector));
stream.ReadExactly(scope.Span);
var result = Read(sector, scope.Span);
return result;
}
internal static async Task<ISector> ReadAsync(ISector sector, Stream stream)
{
using var scope = new ArrayPoolScope<byte>(GetLength(sector));
await stream.ReadExactlyAsync(scope.Memory);
var result = Read(sector, scope.Span);
return result;
}
Modified:
internal static ISector Read(ISector sector, Stream stream)
{
var result = ReadAsync(sector, stream).GetAwaiter().GetResult();
return result;
}
internal static async Task<ISector> ReadAsync(ISector sector, Stream stream)
{
using var scope = new ArrayPoolScope<byte>(GetLength(sector));
await stream.ReadExactlyAsync(scope.Memory);
var result = Read(sector, scope.Span);
return result;
}