Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 4a774b8

Browse files
committed
cancellationToken => token; use .AsValueTask()
1 parent 594a15b commit 4a774b8

31 files changed

+1991
-1993
lines changed

src/ServiceStack.Redis/BasicRedisClientManager.Async.cs

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ private ValueTask<ICacheClientAsync> GetReadOnlyCacheClientAsync(in Cancellation
3636
private IRedisClientAsync ConfigureRedisClientAsync(IRedisClientAsync client)
3737
=> client;
3838

39-
ValueTask<ICacheClientAsync> IRedisClientsManagerAsync.GetCacheClientAsync(CancellationToken cancellationToken)
40-
=> GetCacheClientAsync(cancellationToken);
39+
ValueTask<ICacheClientAsync> IRedisClientsManagerAsync.GetCacheClientAsync(CancellationToken token)
40+
=> GetCacheClientAsync(token);
4141

42-
ValueTask<IRedisClientAsync> IRedisClientsManagerAsync.GetClientAsync(CancellationToken cancellationToken)
42+
ValueTask<IRedisClientAsync> IRedisClientsManagerAsync.GetClientAsync(CancellationToken token)
4343
=> GetClientImpl().AsValueTaskResult<IRedisClientAsync>();
4444

45-
ValueTask<ICacheClientAsync> IRedisClientsManagerAsync.GetReadOnlyCacheClientAsync(CancellationToken cancellationToken)
46-
=> GetReadOnlyCacheClientAsync(cancellationToken);
45+
ValueTask<ICacheClientAsync> IRedisClientsManagerAsync.GetReadOnlyCacheClientAsync(CancellationToken token)
46+
=> GetReadOnlyCacheClientAsync(token);
4747

48-
ValueTask<IRedisClientAsync> IRedisClientsManagerAsync.GetReadOnlyClientAsync(CancellationToken cancellationToken)
48+
ValueTask<IRedisClientAsync> IRedisClientsManagerAsync.GetReadOnlyClientAsync(CancellationToken token)
4949
=> GetReadOnlyClientImpl().AsValueTaskResult<IRedisClientAsync>();
5050

5151
ValueTask IAsyncDisposable.DisposeAsync()
@@ -54,127 +54,127 @@ ValueTask IAsyncDisposable.DisposeAsync()
5454
return default;
5555
}
5656

57-
async Task<T> ICacheClientAsync.GetAsync<T>(string key, CancellationToken cancellationToken)
57+
async Task<T> ICacheClientAsync.GetAsync<T>(string key, CancellationToken token)
5858
{
59-
await using var client = await GetReadOnlyCacheClientAsync(cancellationToken).ConfigureAwait(false);
59+
await using var client = await GetReadOnlyCacheClientAsync(token).ConfigureAwait(false);
6060
return await client.GetAsync<T>(key).ConfigureAwait(false);
6161
}
6262

63-
async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, CancellationToken cancellationToken)
63+
async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, CancellationToken token)
6464
{
65-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
66-
return await client.SetAsync<T>(key, value, cancellationToken).ConfigureAwait(false);
65+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
66+
return await client.SetAsync<T>(key, value, token).ConfigureAwait(false);
6767
}
6868

69-
async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, DateTime expiresAt, CancellationToken cancellationToken)
69+
async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, DateTime expiresAt, CancellationToken token)
7070
{
71-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
72-
return await client.SetAsync<T>(key, value, expiresAt, cancellationToken).ConfigureAwait(false);
71+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
72+
return await client.SetAsync<T>(key, value, expiresAt, token).ConfigureAwait(false);
7373
}
7474

75-
async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, TimeSpan expiresIn, CancellationToken cancellationToken)
75+
async Task<bool> ICacheClientAsync.SetAsync<T>(string key, T value, TimeSpan expiresIn, CancellationToken token)
7676
{
77-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
78-
return await client.SetAsync<T>(key, value, expiresIn, cancellationToken).ConfigureAwait(false);
77+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
78+
return await client.SetAsync<T>(key, value, expiresIn, token).ConfigureAwait(false);
7979
}
8080

81-
async Task ICacheClientAsync.FlushAllAsync(CancellationToken cancellationToken)
81+
async Task ICacheClientAsync.FlushAllAsync(CancellationToken token)
8282
{
83-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
84-
await client.FlushAllAsync(cancellationToken).ConfigureAwait(false);
83+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
84+
await client.FlushAllAsync(token).ConfigureAwait(false);
8585
}
8686

87-
async Task<IDictionary<string, T>> ICacheClientAsync.GetAllAsync<T>(IEnumerable<string> keys, CancellationToken cancellationToken)
87+
async Task<IDictionary<string, T>> ICacheClientAsync.GetAllAsync<T>(IEnumerable<string> keys, CancellationToken token)
8888
{
89-
await using var client = await GetReadOnlyCacheClientAsync(cancellationToken).ConfigureAwait(false);
90-
return await client.GetAllAsync<T>(keys, cancellationToken).ConfigureAwait(false);
89+
await using var client = await GetReadOnlyCacheClientAsync(token).ConfigureAwait(false);
90+
return await client.GetAllAsync<T>(keys, token).ConfigureAwait(false);
9191
}
9292

93-
async Task ICacheClientAsync.SetAllAsync<T>(IDictionary<string, T> values, CancellationToken cancellationToken)
93+
async Task ICacheClientAsync.SetAllAsync<T>(IDictionary<string, T> values, CancellationToken token)
9494
{
95-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
96-
await client.SetAllAsync<T>(values, cancellationToken).ConfigureAwait(false);
95+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
96+
await client.SetAllAsync<T>(values, token).ConfigureAwait(false);
9797
}
9898

99-
async Task<bool> ICacheClientAsync.RemoveAsync(string key, CancellationToken cancellationToken)
99+
async Task<bool> ICacheClientAsync.RemoveAsync(string key, CancellationToken token)
100100
{
101-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
102-
return await client.RemoveAsync(key, cancellationToken).ConfigureAwait(false);
101+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
102+
return await client.RemoveAsync(key, token).ConfigureAwait(false);
103103
}
104104

105-
async Task ICacheClientAsync.RemoveAllAsync(IEnumerable<string> keys, CancellationToken cancellationToken)
105+
async Task ICacheClientAsync.RemoveAllAsync(IEnumerable<string> keys, CancellationToken token)
106106
{
107-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
108-
await client.RemoveAllAsync(keys, cancellationToken).ConfigureAwait(false);
107+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
108+
await client.RemoveAllAsync(keys, token).ConfigureAwait(false);
109109
}
110110

111-
async Task<long> ICacheClientAsync.IncrementAsync(string key, uint amount, CancellationToken cancellationToken)
111+
async Task<long> ICacheClientAsync.IncrementAsync(string key, uint amount, CancellationToken token)
112112
{
113-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
114-
return await client.IncrementAsync(key, amount, cancellationToken).ConfigureAwait(false);
113+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
114+
return await client.IncrementAsync(key, amount, token).ConfigureAwait(false);
115115
}
116116

117-
async Task<long> ICacheClientAsync.DecrementAsync(string key, uint amount, CancellationToken cancellationToken)
117+
async Task<long> ICacheClientAsync.DecrementAsync(string key, uint amount, CancellationToken token)
118118
{
119-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
120-
return await client.DecrementAsync(key, amount, cancellationToken).ConfigureAwait(false);
119+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
120+
return await client.DecrementAsync(key, amount, token).ConfigureAwait(false);
121121
}
122122

123-
async Task<bool> ICacheClientAsync.AddAsync<T>(string key, T value, CancellationToken cancellationToken)
123+
async Task<bool> ICacheClientAsync.AddAsync<T>(string key, T value, CancellationToken token)
124124
{
125-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
126-
return await client.AddAsync<T>(key, value, cancellationToken).ConfigureAwait(false);
125+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
126+
return await client.AddAsync<T>(key, value, token).ConfigureAwait(false);
127127
}
128128

129-
async Task<bool> ICacheClientAsync.ReplaceAsync<T>(string key, T value, CancellationToken cancellationToken)
129+
async Task<bool> ICacheClientAsync.ReplaceAsync<T>(string key, T value, CancellationToken token)
130130
{
131-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
132-
return await client.ReplaceAsync<T>(key, value, cancellationToken).ConfigureAwait(false);
131+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
132+
return await client.ReplaceAsync<T>(key, value, token).ConfigureAwait(false);
133133
}
134134

135-
async Task<bool> ICacheClientAsync.AddAsync<T>(string key, T value, DateTime expiresAt, CancellationToken cancellationToken)
135+
async Task<bool> ICacheClientAsync.AddAsync<T>(string key, T value, DateTime expiresAt, CancellationToken token)
136136
{
137-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
138-
return await client.AddAsync<T>(key, value, expiresAt, cancellationToken).ConfigureAwait(false);
137+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
138+
return await client.AddAsync<T>(key, value, expiresAt, token).ConfigureAwait(false);
139139
}
140140

141-
async Task<bool> ICacheClientAsync.ReplaceAsync<T>(string key, T value, DateTime expiresAt, CancellationToken cancellationToken)
141+
async Task<bool> ICacheClientAsync.ReplaceAsync<T>(string key, T value, DateTime expiresAt, CancellationToken token)
142142
{
143-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
144-
return await client.ReplaceAsync<T>(key, value, expiresAt, cancellationToken).ConfigureAwait(false);
143+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
144+
return await client.ReplaceAsync<T>(key, value, expiresAt, token).ConfigureAwait(false);
145145
}
146146

147-
async Task<bool> ICacheClientAsync.AddAsync<T>(string key, T value, TimeSpan expiresIn, CancellationToken cancellationToken)
147+
async Task<bool> ICacheClientAsync.AddAsync<T>(string key, T value, TimeSpan expiresIn, CancellationToken token)
148148
{
149-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
150-
return await client.AddAsync<T>(key, value, expiresIn, cancellationToken).ConfigureAwait(false);
149+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
150+
return await client.AddAsync<T>(key, value, expiresIn, token).ConfigureAwait(false);
151151
}
152152

153-
async Task<bool> ICacheClientAsync.ReplaceAsync<T>(string key, T value, TimeSpan expiresIn, CancellationToken cancellationToken)
153+
async Task<bool> ICacheClientAsync.ReplaceAsync<T>(string key, T value, TimeSpan expiresIn, CancellationToken token)
154154
{
155-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
156-
return await client.ReplaceAsync<T>(key, value, expiresIn, cancellationToken).ConfigureAwait(false);
155+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
156+
return await client.ReplaceAsync<T>(key, value, expiresIn, token).ConfigureAwait(false);
157157
}
158158

159-
async Task<TimeSpan?> ICacheClientAsync.GetTimeToLiveAsync(string key, CancellationToken cancellationToken)
159+
async Task<TimeSpan?> ICacheClientAsync.GetTimeToLiveAsync(string key, CancellationToken token)
160160
{
161-
await using var client = await GetReadOnlyCacheClientAsync(cancellationToken).ConfigureAwait(false);
162-
return await client.GetTimeToLiveAsync(key, cancellationToken).ConfigureAwait(false);
161+
await using var client = await GetReadOnlyCacheClientAsync(token).ConfigureAwait(false);
162+
return await client.GetTimeToLiveAsync(key, token).ConfigureAwait(false);
163163
}
164164

165-
async IAsyncEnumerable<string> ICacheClientAsync.GetKeysByPatternAsync(string pattern, [EnumeratorCancellation] CancellationToken cancellationToken)
165+
async IAsyncEnumerable<string> ICacheClientAsync.GetKeysByPatternAsync(string pattern, [EnumeratorCancellation] CancellationToken token)
166166
{
167-
await using var client = await GetReadOnlyCacheClientAsync(cancellationToken).ConfigureAwait(false);
168-
await foreach (var key in client.GetKeysByPatternAsync(pattern, cancellationToken).ConfigureAwait(false).WithCancellation(cancellationToken))
167+
await using var client = await GetReadOnlyCacheClientAsync(token).ConfigureAwait(false);
168+
await foreach (var key in client.GetKeysByPatternAsync(pattern, token).ConfigureAwait(false).WithCancellation(token))
169169
{
170170
yield return key;
171171
}
172172
}
173173

174-
async Task ICacheClientAsync.RemoveExpiredEntriesAsync(CancellationToken cancellationToken)
174+
async Task ICacheClientAsync.RemoveExpiredEntriesAsync(CancellationToken token)
175175
{
176-
await using var client = await GetCacheClientAsync(cancellationToken).ConfigureAwait(false);
177-
await client.RemoveExpiredEntriesAsync(cancellationToken).ConfigureAwait(false);
176+
await using var client = await GetCacheClientAsync(token).ConfigureAwait(false);
177+
await client.RemoveExpiredEntriesAsync(token).ConfigureAwait(false);
178178
}
179179
}
180180
}

src/ServiceStack.Redis/BufferedReader.Async.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ namespace ServiceStack.Redis
77
{
88
internal sealed partial class BufferedReader
99
{
10-
internal ValueTask<int> ReadByteAsync(in CancellationToken cancellationToken = default)
11-
=> _available > 0 ? ReadByteFromBuffer().AsValueTaskResult() : ReadByteSlowAsync(cancellationToken);
10+
internal ValueTask<int> ReadByteAsync(in CancellationToken token = default)
11+
=> _available > 0 ? ReadByteFromBuffer().AsValueTaskResult() : ReadByteSlowAsync(token);
1212

13-
private ValueTask<int> ReadByteSlowAsync(in CancellationToken cancellationToken)
13+
private ValueTask<int> ReadByteSlowAsync(in CancellationToken token)
1414
{
15-
cancellationToken.ThrowIfCancellationRequested();
15+
token.ThrowIfCancellationRequested();
1616
_offset = 0;
1717
#if ASYNC_MEMORY
18-
var pending = _source.ReadAsync(new Memory<byte>(_buffer), cancellationToken);
18+
var pending = _source.ReadAsync(new Memory<byte>(_buffer), token);
1919
if (!pending.IsCompletedSuccessfully)
2020
return Awaited(this, pending);
2121
#else
22-
var pending = _source.ReadAsync(_buffer, 0, _buffer.Length, cancellationToken);
22+
var pending = _source.ReadAsync(_buffer, 0, _buffer.Length, token);
2323
if (pending.Status != TaskStatus.RanToCompletion)
2424
return Awaited(this, pending);
2525
#endif
@@ -42,27 +42,27 @@ static async ValueTask<int> Awaited(BufferedReader @this, Task<int> pending)
4242
#endif
4343
}
4444

45-
internal ValueTask<int> ReadAsync(byte[] buffer, int offset, int count, in CancellationToken cancellationToken = default)
45+
internal ValueTask<int> ReadAsync(byte[] buffer, int offset, int count, in CancellationToken token = default)
4646
=> _available > 0
4747
? ReadFromBuffer(buffer, offset, count).AsValueTaskResult()
48-
: ReadSlowAsync(buffer, offset, count, cancellationToken);
48+
: ReadSlowAsync(buffer, offset, count, token);
4949

50-
private ValueTask<int> ReadSlowAsync(byte[] buffer, int offset, int count, in CancellationToken cancellationToken)
50+
private ValueTask<int> ReadSlowAsync(byte[] buffer, int offset, int count, in CancellationToken token)
5151
{
5252
// if they're asking for more than we deal in, just step out of the way
5353
if (count >= buffer.Length)
5454
{
5555
#if ASYNC_MEMORY
56-
return _source.ReadAsync(new Memory<byte>(buffer, offset, count), cancellationToken);
56+
return _source.ReadAsync(new Memory<byte>(buffer, offset, count), token);
5757
#else
58-
return new ValueTask<int>(_source.ReadAsync(buffer, offset, count, cancellationToken));
58+
return new ValueTask<int>(_source.ReadAsync(buffer, offset, count, token));
5959
#endif
6060
}
6161

6262
// they're asking for less, so we could still have some left
6363
_offset = 0;
6464
#if ASYNC_MEMORY
65-
var pending = _source.ReadAsync(new Memory<byte>(_buffer), cancellationToken);
65+
var pending = _source.ReadAsync(new Memory<byte>(_buffer), token);
6666
if (!pending.IsCompletedSuccessfully)
6767
return Awaited(this, pending, buffer, offset, count);
6868

@@ -75,7 +75,7 @@ static async ValueTask<int> Awaited(BufferedReader @this, ValueTask<int> pending
7575
return @this._available > 0 ? @this.ReadFromBuffer(buffer, offset, count) : 0;
7676
}
7777
#else
78-
var pending = _source.ReadAsync(_buffer, 0, _buffer.Length, cancellationToken);
78+
var pending = _source.ReadAsync(_buffer, 0, _buffer.Length, token);
7979
if (pending.Status != TaskStatus.RanToCompletion)
8080
return Awaited(this, pending, buffer, offset, count);
8181

0 commit comments

Comments
 (0)