Less await
This commit is contained in:
Родитель
f175ebfdd1
Коммит
ec28bf3f18
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Peregrine
|
||||
{
|
||||
internal sealed class AwaitableSocket : INotifyCompletion, IDisposable
|
||||
public sealed class AwaitableSocket : INotifyCompletion, IDisposable
|
||||
{
|
||||
private static readonly Action Sentinel = () => { };
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace Peregrine
|
|||
}
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(string statementName)
|
||||
public AwaitableSocket ExecuteAsync(string statementName)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
ThrowIfNotConnected();
|
||||
|
@ -135,7 +135,7 @@ namespace Peregrine
|
|||
.WriteShort(1)
|
||||
.WriteShort(parameterCount);
|
||||
|
||||
private Task WriteExecFinish()
|
||||
private AwaitableSocket WriteExecFinish()
|
||||
=> _writeBuffer
|
||||
.WriteShort(1)
|
||||
.WriteShort(1)
|
||||
|
@ -292,7 +292,7 @@ namespace Peregrine
|
|||
}
|
||||
}
|
||||
|
||||
private Task WriteStartupAsync()
|
||||
private AwaitableSocket WriteStartupAsync()
|
||||
{
|
||||
const int protocolVersion3 = 3 << 16;
|
||||
|
||||
|
|
|
@ -110,19 +110,6 @@ namespace Peregrine
|
|||
var s = PG.UTF8.GetString(span.Slice(start, _position - start - 1));
|
||||
|
||||
return s;
|
||||
|
||||
// var span = _buffer.Span;
|
||||
// var length = _position;
|
||||
//
|
||||
// while (span[length++] != 0
|
||||
// && length < _buffer.Length)
|
||||
// {
|
||||
// var x = span[length];
|
||||
// }
|
||||
//
|
||||
// var result = PG.UTF8.GetString(span.Slice(_position, length - _position - 1));
|
||||
// _position += length;
|
||||
// return result;
|
||||
}
|
||||
|
||||
public string ReadString(int length)
|
||||
|
@ -132,20 +119,12 @@ namespace Peregrine
|
|||
return result;
|
||||
}
|
||||
|
||||
public async Task ReceiveAsync()
|
||||
public AwaitableSocket ReceiveAsync()
|
||||
{
|
||||
_awaitableSocket.SetBuffer(_buffer);
|
||||
|
||||
await _awaitableSocket.ReceiveAsync();
|
||||
|
||||
var bytesTransferred = _awaitableSocket.BytesTransferred;
|
||||
|
||||
if (bytesTransferred == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
|
||||
_position = 0;
|
||||
|
||||
return _awaitableSocket.ReceiveAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,13 +96,12 @@ namespace Peregrine
|
|||
return WriteNull();
|
||||
}
|
||||
|
||||
public async Task FlushAsync()
|
||||
public AwaitableSocket FlushAsync()
|
||||
{
|
||||
_awaitableSocket.SetBuffer(_buffer, 0, _position);
|
||||
|
||||
await _awaitableSocket.SendAsync();
|
||||
|
||||
_position = 0;
|
||||
|
||||
return _awaitableSocket.SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче