-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathEtcdClientWrapper.cs
More file actions
54 lines (46 loc) · 1.84 KB
/
Copy pathEtcdClientWrapper.cs
File metadata and controls
54 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using dotnet_etcd.interfaces;
using Etcdserverpb;
using Grpc.Core;
using Medallion.Threading.Internal;
using V3Lockpb;
namespace Medallion.Threading.Etcd;
internal class EtcdClientWrapper
{
private readonly IEtcdClient _etcdClient;
public EtcdClientWrapper(IEtcdClient etcdClient)
{
this._etcdClient = etcdClient ?? throw new ArgumentNullException(nameof(etcdClient));
}
public ValueTask<LeaseGrantResponse> LeaseGrantAsync(LeaseGrantRequest request, CancellationToken cancellationToken)
{
return SyncViaAsync.IsSynchronous
? new ValueTask<LeaseGrantResponse>(this._etcdClient.LeaseGrant(request,
cancellationToken: cancellationToken))
: new ValueTask<LeaseGrantResponse>(
this._etcdClient.LeaseGrantAsync(request, cancellationToken: cancellationToken));
}
public Task LeaseKeepAliveAsync(long leaseId, CancellationToken token)
=> this._etcdClient.LeaseKeepAlive(leaseId, token);
public async ValueTask<LockResponse> LockAsync(LockRequest lockRequest, CancellationToken cancellationToken)
{
var response = SyncViaAsync.IsSynchronous
? this._etcdClient.Lock(lockRequest, cancellationToken: cancellationToken)
: await this._etcdClient.LockAsync(lockRequest, cancellationToken: cancellationToken).ConfigureAwait(false);
if (response == null)
{
throw new RpcException(new Status(StatusCode.Internal, "Lock failed"));
}
return response;
}
public async ValueTask LeaseRevokeAsync(LeaseRevokeRequest leaseRevokeRequest)
{
if (SyncViaAsync.IsSynchronous)
{
this._etcdClient.LeaseRevoke(leaseRevokeRequest);
}
else
{
await this._etcdClient.LeaseRevokeAsync(leaseRevokeRequest).ConfigureAwait(false);
}
}
}