mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-06 23:15:16 +00:00
Improvements for async methods
Added CancellationToken with default value to all async methods in TLSharp.Core Added ConfigureAwait(false) to all async methods in TLSharp.Core SendRequestAsync replaced to SendAuthenticatedRequestAsync in methods that need auth Private modifier in SendAuthenticatedRequestAsync changed to internal Based on PR created by @IaRuslan
This commit is contained in:
parent
1ccafe22a3
commit
c5a2c816fc
6 changed files with 198 additions and 141 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TLSharp.Core.Network
|
||||
|
|
@ -17,8 +18,10 @@ namespace TLSharp.Core.Network
|
|||
random = new Random();
|
||||
}
|
||||
|
||||
public async Task Send(byte[] data)
|
||||
public async Task Send(byte[] data, CancellationToken token = default(CancellationToken))
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
using (var binaryWriter = new BinaryWriter(memoryStream))
|
||||
|
|
@ -30,14 +33,16 @@ namespace TLSharp.Core.Network
|
|||
|
||||
byte[] packet = memoryStream.ToArray();
|
||||
|
||||
await _transport.Send(packet);
|
||||
await _transport.Send(packet, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<byte[]> Receive()
|
||||
public async Task<byte[]> Receive(CancellationToken token = default(CancellationToken))
|
||||
{
|
||||
var result = await _transport.Receive();
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
var result = await _transport.Receive(token).ConfigureAwait(false);
|
||||
|
||||
using (var memoryStream = new MemoryStream(result.Body))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue