[#13] Add cancellation token to GetChank method
All checks were successful
DCO / DCO (pull_request) Successful in 40s
All checks were successful
DCO / DCO (pull_request) Successful in 40s
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
f5d1899dd2
commit
17492ee871
2 changed files with 6 additions and 4 deletions
|
@ -5,13 +5,14 @@ using Grpc.Core;
|
||||||
|
|
||||||
using FrostFS.Object;
|
using FrostFS.Object;
|
||||||
using FrostFS.SDK.ModelsV2;
|
using FrostFS.SDK.ModelsV2;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace FrostFS.SDK.ClientV2;
|
namespace FrostFS.SDK.ClientV2;
|
||||||
|
|
||||||
public class ObjectReader(AsyncServerStreamingCall<GetResponse> call) : IObjectReader
|
public class ObjectReader(AsyncServerStreamingCall<GetResponse> call) : IObjectReader
|
||||||
{
|
{
|
||||||
private bool disposed = false;
|
private bool disposed = false;
|
||||||
|
|
||||||
public AsyncServerStreamingCall<GetResponse> Call { get; private set; } = call;
|
public AsyncServerStreamingCall<GetResponse> Call { get; private set; } = call;
|
||||||
|
|
||||||
internal async Task<Object.Object> ReadHeader()
|
internal async Task<Object.Object> ReadHeader()
|
||||||
|
@ -32,9 +33,9 @@ public class ObjectReader(AsyncServerStreamingCall<GetResponse> call) : IObjectR
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]?> ReadChunk()
|
public async Task<byte[]?> ReadChunk(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (!await Call.ResponseStream.MoveNext())
|
if (!await Call.ResponseStream.MoveNext(cancellationToken))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var response = Call.ResponseStream.Current;
|
var response = Call.ResponseStream.Current;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FrostFS.SDK.ModelsV2;
|
namespace FrostFS.SDK.ModelsV2;
|
||||||
|
|
||||||
public interface IObjectReader : IDisposable
|
public interface IObjectReader : IDisposable
|
||||||
{
|
{
|
||||||
Task<byte[]?> ReadChunk();
|
Task<byte[]?> ReadChunk(CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue