Skip to content

Commit

Permalink
chore: set timeout at client instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce committed Dec 21, 2023
1 parent 84abbd6 commit 1f9cb8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/src/cache_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'messages/values.dart';
abstract class ICacheClient {
Future<GetResponse> get(String cacheName, Value value);

Future<SetResponse> subscribe(String cacheName, Value key, Value value,
Future<SetResponse> set(String cacheName, Value key, Value value,
{int? ttlSeconds});
}

Expand All @@ -33,7 +33,7 @@ class CacheClient implements ICacheClient {
}

@override
Future<SetResponse> subscribe(String cacheName, Value key, Value value,
Future<SetResponse> set(String cacheName, Value key, Value value,
{int? ttlSeconds}) {
return _dataClient.set(cacheName, key, value, ttlSeconds: ttlSeconds);
}
Expand Down
20 changes: 8 additions & 12 deletions lib/src/internal/data_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DataClient implements AbstractDataClient {
_client = ScsClient(_channel,
options: CallOptions(metadata: {
'authorization': credentialProvider.apiKey,
'agent': 'dart:0.1.0'
}));
'agent': 'dart:0.1.0',
}, timeout: _configuration.transportStrategy.grpcConfig.deadline));
_configuration = configuration;
_defaultTtl = defaultTtl;
}
Expand All @@ -40,11 +40,9 @@ class DataClient implements AbstractDataClient {
request.cacheKey = key.toBinary();
try {
var resp = await _client.get(request,
options: CallOptions(
timeout: _configuration.transportStrategy.grpcConfig.deadline,
metadata: {
'cacheName': cacheName,
}));
options: CallOptions(metadata: {
'cacheName': cacheName,
}));

switch (resp.result) {
case ECacheResult.Miss:
Expand Down Expand Up @@ -75,11 +73,9 @@ class DataClient implements AbstractDataClient {
: _defaultTtl.inMilliseconds) as Int64;
try {
await _client.set(request,
options: CallOptions(
timeout: _configuration.transportStrategy.grpcConfig.deadline,
metadata: {
'cacheName': cacheName,
}));
options: CallOptions(metadata: {
'cacheName': cacheName,
}));
return SetSuccess();
} catch (e) {
if (e is SdkException) {
Expand Down

0 comments on commit 1f9cb8e

Please sign in to comment.