| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Threading; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using Etcdserverpb; |
| | | 7 | | using Google.Protobuf; |
| | | 8 | | using Grpc.Core; |
| | | 9 | | |
| | | 10 | | namespace dotnet_etcd; |
| | | 11 | | |
| | | 12 | | public partial class EtcdClient |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Watches the specified requests and passes the watch events to the methods provided asynchronously. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="requests">Watch Requests containing keys to be watched</param> |
| | | 18 | | /// <param name="methods">Methods to which watch events should be passed on</param> |
| | | 19 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 20 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 21 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 22 | | /// <returns>A task that completes with an array of watch IDs</returns> |
| | | 23 | | public async Task<long[]> WatchAsync(WatchRequest[] requests, Action<WatchEvent[]>[] methods, |
| | | 24 | | Metadata headers = null, |
| | | 25 | | DateTime? deadline = null, |
| | | 26 | | CancellationToken cancellationToken = default) |
| | 0 | 27 | | { |
| | 0 | 28 | | if (requests.Length != methods.Length) |
| | 0 | 29 | | { |
| | 0 | 30 | | throw new ArgumentException("The number of requests must match the number of methods"); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | long[] watchIds = new long[requests.Length]; |
| | | 34 | | |
| | 0 | 35 | | for (int i = 0; i < requests.Length; i++) |
| | 0 | 36 | | { |
| | | 37 | | // Create a wrapper that converts WatchResponse to WatchEvent[] |
| | 0 | 38 | | Action<WatchResponse> wrapper = response => |
| | 0 | 39 | | { |
| | 0 | 40 | | WatchEvent[] events = response.Events.Select(e => new WatchEvent |
| | 0 | 41 | | { |
| | 0 | 42 | | Key = e.Kv.Key.ToStringUtf8(), Value = e.Kv.Value.ToStringUtf8(), Type = e.Type |
| | 0 | 43 | | }).ToArray(); |
| | 0 | 44 | | |
| | 0 | 45 | | methods[i](events); |
| | 0 | 46 | | }; |
| | | 47 | | |
| | 0 | 48 | | watchIds[i] = await _watchManager.WatchAsync(requests[i], wrapper, headers, deadline, cancellationToken) |
| | 0 | 49 | | .ConfigureAwait(false); |
| | 0 | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | return watchIds; |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | public Task<long[]> WatchAsync(WatchRequest[] requests, Action<WatchEvent[]> method, Metadata headers = null, |
| | | 56 | | DateTime? deadline = null, CancellationToken cancellationToken = default) |
| | 0 | 57 | | { |
| | 0 | 58 | | List<Task<long>> tasks = []; |
| | | 59 | | |
| | 0 | 60 | | foreach (WatchRequest request in requests) |
| | 0 | 61 | | { |
| | | 62 | | // Create a wrapper that converts WatchResponse to WatchEvent[] |
| | 0 | 63 | | Action<WatchResponse> wrapper = response => |
| | 0 | 64 | | { |
| | 0 | 65 | | WatchEvent[] events = response.Events.Select(e => new WatchEvent |
| | 0 | 66 | | { |
| | 0 | 67 | | Key = e.Kv.Key.ToStringUtf8(), Value = e.Kv.Value.ToStringUtf8(), Type = e.Type |
| | 0 | 68 | | }).ToArray(); |
| | 0 | 69 | | |
| | 0 | 70 | | method(events); |
| | 0 | 71 | | }; |
| | | 72 | | |
| | 0 | 73 | | tasks.Add(_watchManager.WatchAsync(request, wrapper, headers, deadline, cancellationToken)); |
| | 0 | 74 | | } |
| | | 75 | | |
| | 0 | 76 | | return Task.WhenAll(tasks); |
| | 0 | 77 | | } |
| | | 78 | | // CancelWatch methods are already defined in EtcdClient.cs |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Watches the specified requests and passes the watch response to the methods provided. |
| | | 82 | | /// </summary> |
| | | 83 | | /// <param name="requests">Watch Requests containing keys to be watched</param> |
| | | 84 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 85 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 86 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 87 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 88 | | public void Watch(WatchRequest[] requests, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 89 | | DateTime? deadline = null, |
| | | 90 | | CancellationToken cancellationToken = default) |
| | 0 | 91 | | { |
| | 0 | 92 | | if (requests.Length != methods.Length) |
| | 0 | 93 | | { |
| | 0 | 94 | | throw new ArgumentException("The number of requests must match the number of methods"); |
| | | 95 | | } |
| | | 96 | | |
| | 0 | 97 | | for (int i = 0; i < requests.Length; i++) |
| | 0 | 98 | | { |
| | 0 | 99 | | _watchManager.Watch(requests[i], methods[i], headers, deadline, cancellationToken); |
| | 0 | 100 | | } |
| | 0 | 101 | | } |
| | | 102 | | |
| | | 103 | | /// <summary> |
| | | 104 | | /// Watches the specified requests and passes the watch events to the methods provided. |
| | | 105 | | /// </summary> |
| | | 106 | | /// <param name="requests">Watch Requests containing keys to be watched</param> |
| | | 107 | | /// <param name="methods">Methods to which watch events should be passed on</param> |
| | | 108 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 109 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 110 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 111 | | public void Watch(WatchRequest[] requests, Action<WatchEvent[]>[] methods, Metadata headers = null, |
| | | 112 | | DateTime? deadline = null, |
| | | 113 | | CancellationToken cancellationToken = default) |
| | 0 | 114 | | { |
| | 0 | 115 | | if (requests.Length != methods.Length) |
| | 0 | 116 | | { |
| | 0 | 117 | | throw new ArgumentException("The number of requests must match the number of methods"); |
| | | 118 | | } |
| | | 119 | | |
| | 0 | 120 | | for (int i = 0; i < requests.Length; i++) |
| | 0 | 121 | | { |
| | | 122 | | // Create a wrapper that converts WatchResponse to WatchEvent[] |
| | 0 | 123 | | Action<WatchResponse> wrapper = response => |
| | 0 | 124 | | { |
| | 0 | 125 | | WatchEvent[] events = [.. response.Events.Select(e => new WatchEvent |
| | 0 | 126 | | { |
| | 0 | 127 | | Key = e.Kv.Key.ToStringUtf8(), Value = e.Kv.Value.ToStringUtf8(), Type = e.Type |
| | 0 | 128 | | })]; |
| | 0 | 129 | | |
| | 0 | 130 | | methods[i](events); |
| | 0 | 131 | | }; |
| | | 132 | | |
| | 0 | 133 | | _watchManager.Watch(requests[i], wrapper, headers, deadline, cancellationToken); |
| | 0 | 134 | | } |
| | 0 | 135 | | } |
| | | 136 | | |
| | | 137 | | #region Watch Key |
| | | 138 | | |
| | | 139 | | /// <summary> |
| | | 140 | | /// Watches a key according to the specified watch request and |
| | | 141 | | /// passes the watch response to the method provided. |
| | | 142 | | /// </summary> |
| | | 143 | | /// <param name="request">Watch Request containing a key to be watched</param> |
| | | 144 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 145 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 146 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 147 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 148 | | /// <returns>A task that completes with the watch ID</returns> |
| | | 149 | | public Task<long> WatchAsync(WatchRequest request, Action<WatchResponse> method, Metadata headers = null, |
| | | 150 | | DateTime? deadline = null, |
| | | 151 | | CancellationToken cancellationToken = default) => |
| | 0 | 152 | | _watchManager.WatchAsync(request, method, headers, deadline, cancellationToken); |
| | | 153 | | |
| | | 154 | | /// <summary> |
| | | 155 | | /// Watches a key according to the specified watch request and |
| | | 156 | | /// passes the watch response to the methods provided. |
| | | 157 | | /// </summary> |
| | | 158 | | /// <param name="request">Watch Request containing a key to be watched</param> |
| | | 159 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 160 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 161 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 162 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 163 | | /// <returns>A task that completes with the watch ID</returns> |
| | | 164 | | public Task<long> WatchAsync(WatchRequest request, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 165 | | DateTime? deadline = null, |
| | | 166 | | CancellationToken cancellationToken = default) |
| | 0 | 167 | | { |
| | | 168 | | // Create a wrapper method that calls all the methods |
| | 0 | 169 | | Action<WatchResponse> wrapper = response => |
| | 0 | 170 | | { |
| | 0 | 171 | | foreach (Action<WatchResponse> method in methods) |
| | 0 | 172 | | { |
| | 0 | 173 | | method(response); |
| | 0 | 174 | | } |
| | 0 | 175 | | }; |
| | | 176 | | |
| | 0 | 177 | | return _watchManager.WatchAsync(request, wrapper, headers, deadline, cancellationToken); |
| | 0 | 178 | | } |
| | | 179 | | |
| | | 180 | | /// <summary> |
| | | 181 | | /// Watches a key according to the specified watch requests and |
| | | 182 | | /// passes the watch response to the method provided. |
| | | 183 | | /// </summary> |
| | | 184 | | /// <param name="requests">Watch Requests containing keys to be watched</param> |
| | | 185 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 186 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 187 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 188 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 189 | | /// <returns>A task that completes with an array of watch IDs</returns> |
| | | 190 | | public async Task<long[]> WatchAsync(WatchRequest[] requests, Action<WatchResponse> method, Metadata headers = null, |
| | | 191 | | DateTime? deadline = null, |
| | | 192 | | CancellationToken cancellationToken = default) |
| | 0 | 193 | | { |
| | 0 | 194 | | long[] watchIds = new long[requests.Length]; |
| | | 195 | | |
| | 0 | 196 | | for (int i = 0; i < requests.Length; i++) |
| | 0 | 197 | | { |
| | 0 | 198 | | watchIds[i] = await _watchManager.WatchAsync(requests[i], method, headers, deadline, cancellationToken) |
| | 0 | 199 | | .ConfigureAwait(false); |
| | 0 | 200 | | } |
| | | 201 | | |
| | 0 | 202 | | return watchIds; |
| | 0 | 203 | | } |
| | | 204 | | |
| | | 205 | | /// <summary> |
| | | 206 | | /// Watches a key according to the specified watch requests and |
| | | 207 | | /// passes the watch response to the methods provided. |
| | | 208 | | /// </summary> |
| | | 209 | | /// <param name="requests">Watch Requests containing keys to be watched</param> |
| | | 210 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 211 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 212 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 213 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 214 | | /// <returns>A task that completes with an array of watch IDs</returns> |
| | | 215 | | public async Task<long[]> WatchAsync(WatchRequest[] requests, Action<WatchResponse>[] methods, |
| | | 216 | | Metadata headers = null, |
| | | 217 | | DateTime? deadline = null, |
| | | 218 | | CancellationToken cancellationToken = default) |
| | 0 | 219 | | { |
| | 0 | 220 | | if (requests.Length != methods.Length) |
| | 0 | 221 | | { |
| | 0 | 222 | | throw new ArgumentException("The number of requests must match the number of methods"); |
| | | 223 | | } |
| | | 224 | | |
| | 0 | 225 | | long[] watchIds = new long[requests.Length]; |
| | | 226 | | |
| | 0 | 227 | | for (int i = 0; i < requests.Length; i++) |
| | 0 | 228 | | { |
| | 0 | 229 | | watchIds[i] = await _watchManager.WatchAsync(requests[i], methods[i], headers, deadline, cancellationToken) |
| | 0 | 230 | | .ConfigureAwait(false); |
| | 0 | 231 | | } |
| | | 232 | | |
| | 0 | 233 | | return watchIds; |
| | 0 | 234 | | } |
| | | 235 | | |
| | | 236 | | /// <summary> |
| | | 237 | | /// Watches a key according to the specified watch request and |
| | | 238 | | /// passes the minimal watch event data to the method provided. |
| | | 239 | | /// </summary> |
| | | 240 | | /// <param name="request">Watch Request containing a key to be watched</param> |
| | | 241 | | /// <param name="method">Method to which minimal watch events data should be passed on</param> |
| | | 242 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 243 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 244 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 245 | | public Task WatchAsync(WatchRequest request, Action<WatchEvent[]> method, Metadata headers = null, |
| | | 246 | | DateTime? deadline = null, |
| | | 247 | | CancellationToken cancellationToken = default) |
| | 0 | 248 | | { |
| | | 249 | | // Create a wrapper that converts WatchResponse to WatchEvent[] |
| | 0 | 250 | | Action<WatchResponse> wrapper = response => |
| | 0 | 251 | | { |
| | 0 | 252 | | WatchEvent[] events = response.Events.Select(i => |
| | 0 | 253 | | { |
| | 0 | 254 | | return new WatchEvent |
| | 0 | 255 | | { |
| | 0 | 256 | | Key = i.Kv.Key.ToStringUtf8(), Value = i.Kv.Value.ToStringUtf8(), Type = i.Type |
| | 0 | 257 | | }; |
| | 0 | 258 | | }).ToArray(); |
| | 0 | 259 | | |
| | 0 | 260 | | method(events); |
| | 0 | 261 | | }; |
| | | 262 | | |
| | 0 | 263 | | return _watchManager.WatchAsync(request, wrapper, headers, deadline, cancellationToken); |
| | 0 | 264 | | } |
| | | 265 | | |
| | | 266 | | /// <summary> |
| | | 267 | | /// Watches a key according to the specified watch request and |
| | | 268 | | /// passes the minimal watch event data to the methods provided. |
| | | 269 | | /// </summary> |
| | | 270 | | /// <param name="request">Watch Request containing a key to be watched</param> |
| | | 271 | | /// <param name="methods">Methods to which minimal watch events data should be passed on</param> |
| | | 272 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 273 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 274 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 275 | | public Task WatchAsync(WatchRequest request, Action<WatchEvent[]>[] methods, Metadata headers = null, |
| | | 276 | | DateTime? deadline = null, |
| | | 277 | | CancellationToken cancellationToken = default) |
| | 0 | 278 | | { |
| | | 279 | | // Create a wrapper that converts WatchResponse to WatchEvent[] and calls all methods |
| | 0 | 280 | | Action<WatchResponse> wrapper = response => |
| | 0 | 281 | | { |
| | 0 | 282 | | WatchEvent[] events = response.Events.Select(i => |
| | 0 | 283 | | { |
| | 0 | 284 | | return new WatchEvent |
| | 0 | 285 | | { |
| | 0 | 286 | | Key = i.Kv.Key.ToStringUtf8(), Value = i.Kv.Value.ToStringUtf8(), Type = i.Type |
| | 0 | 287 | | }; |
| | 0 | 288 | | }).ToArray(); |
| | 0 | 289 | | |
| | 0 | 290 | | foreach (Action<WatchEvent[]> method in methods) |
| | 0 | 291 | | { |
| | 0 | 292 | | method(events); |
| | 0 | 293 | | } |
| | 0 | 294 | | }; |
| | | 295 | | |
| | 0 | 296 | | return _watchManager.WatchAsync(request, wrapper, headers, deadline, cancellationToken); |
| | 0 | 297 | | } |
| | | 298 | | |
| | | 299 | | /// <summary> |
| | | 300 | | /// Watches the specified key and passes the watch response to the method provided. |
| | | 301 | | /// </summary> |
| | | 302 | | /// <param name="request">Watch Request</param> |
| | | 303 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 304 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 305 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 306 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 307 | | public void Watch(WatchRequest request, Action<WatchResponse> method, Metadata headers = null, |
| | | 308 | | DateTime? deadline = null, |
| | | 309 | | CancellationToken cancellationToken = default) => |
| | 0 | 310 | | _watchManager.Watch(request, method, headers, deadline, cancellationToken); |
| | | 311 | | |
| | | 312 | | /// <summary> |
| | | 313 | | /// Watches a key according to the specified watch request and |
| | | 314 | | /// passes the watch response to the methods provided. |
| | | 315 | | /// </summary> |
| | | 316 | | /// <param name="request">Watch Request containing a key to be watched</param> |
| | | 317 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 318 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 319 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 320 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 321 | | public void Watch(WatchRequest request, Action<WatchResponse>[] methods, |
| | | 322 | | Metadata headers = null, DateTime? deadline = null, |
| | 0 | 323 | | CancellationToken cancellationToken = default) => Watch([request], methods, headers, |
| | 0 | 324 | | deadline, cancellationToken); |
| | | 325 | | |
| | | 326 | | |
| | | 327 | | /// <summary> |
| | | 328 | | /// Watches the specified keys and passes the watch response to the method provided. |
| | | 329 | | /// </summary> |
| | | 330 | | /// <param name="key">Key to watch</param> |
| | | 331 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 332 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 333 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 334 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 335 | | public void Watch(string key, Action<WatchResponse> method, Metadata headers = null, |
| | | 336 | | DateTime? deadline = null, |
| | 0 | 337 | | CancellationToken cancellationToken = default) => Watch([key], |
| | 0 | 338 | | [method], headers, deadline, cancellationToken); |
| | | 339 | | |
| | | 340 | | /// <summary> |
| | | 341 | | /// Watches the specified key and passes the watch response to the methods provided. |
| | | 342 | | /// </summary> |
| | | 343 | | /// <param name="key">Key to be watched</param> |
| | | 344 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 345 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 346 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 347 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 348 | | public void Watch(string key, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 349 | | DateTime? deadline = null, |
| | | 350 | | CancellationToken cancellationToken = default) => |
| | 0 | 351 | | Watch([key], methods, headers, deadline, cancellationToken); |
| | | 352 | | |
| | | 353 | | |
| | | 354 | | /// <summary> |
| | | 355 | | /// Watches the specified keys and passes the watch response to the method provided. |
| | | 356 | | /// </summary> |
| | | 357 | | /// <param name="keys">Keys to be watched</param> |
| | | 358 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 359 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 360 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 361 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 362 | | public void Watch(string[] keys, Action<WatchResponse> method, Metadata headers = null, |
| | | 363 | | DateTime? deadline = null, |
| | 0 | 364 | | CancellationToken cancellationToken = default) => Watch(keys, [method], headers, |
| | 0 | 365 | | deadline, cancellationToken); |
| | | 366 | | |
| | | 367 | | /// <summary> |
| | | 368 | | /// Watches the specified keys and passes the watch response to the method provided. |
| | | 369 | | /// </summary> |
| | | 370 | | /// <param name="keys">Keys to be watched</param> |
| | | 371 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 372 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 373 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 374 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 375 | | public void Watch(string[] keys, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 376 | | DateTime? deadline = null, |
| | | 377 | | CancellationToken cancellationToken = default) |
| | 0 | 378 | | { |
| | 0 | 379 | | List<WatchRequest> requests = []; |
| | | 380 | | |
| | 0 | 381 | | foreach (string key in keys) |
| | 0 | 382 | | { |
| | 0 | 383 | | WatchRequest request = new() |
| | 0 | 384 | | { |
| | 0 | 385 | | CreateRequest = new WatchCreateRequest |
| | 0 | 386 | | { |
| | 0 | 387 | | Key = ByteString.CopyFromUtf8(key), ProgressNotify = true, PrevKv = true |
| | 0 | 388 | | } |
| | 0 | 389 | | }; |
| | 0 | 390 | | requests.Add(request); |
| | 0 | 391 | | } |
| | | 392 | | |
| | 0 | 393 | | Watch(requests.ToArray(), methods, headers, deadline, cancellationToken); |
| | 0 | 394 | | } |
| | | 395 | | |
| | | 396 | | |
| | | 397 | | /// <summary> |
| | | 398 | | /// Watches the specified key and passes the minimal watch events data to the method provided. |
| | | 399 | | /// </summary> |
| | | 400 | | /// <param name="key">Key to be watched</param> |
| | | 401 | | /// <param name="method">Method to which minimal watch events data should be passed on</param> |
| | | 402 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 403 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 404 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 405 | | public void Watch(string key, Action<WatchEvent[]> method, Metadata headers = null, |
| | | 406 | | DateTime? deadline = null, |
| | 0 | 407 | | CancellationToken cancellationToken = default) => Watch([key], |
| | 0 | 408 | | [method], headers, deadline, cancellationToken); |
| | | 409 | | |
| | | 410 | | /// <summary> |
| | | 411 | | /// Watches the specified key and passes the minimal watch events data to the methods provided. |
| | | 412 | | /// </summary> |
| | | 413 | | /// <param name="key">Key to be watched</param> |
| | | 414 | | /// <param name="methods">Methods to which minimal watch events data should be passed on</param> |
| | | 415 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 416 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 417 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 418 | | public void Watch(string key, Action<WatchEvent[]>[] methods, Metadata headers = null, |
| | | 419 | | DateTime? deadline = null, |
| | | 420 | | CancellationToken cancellationToken = default) => |
| | 0 | 421 | | Watch([key], methods, headers, deadline, cancellationToken); |
| | | 422 | | |
| | | 423 | | /// <summary> |
| | | 424 | | /// Watches the specified keys and passes the minimal watch events data to the method provided. |
| | | 425 | | /// </summary> |
| | | 426 | | /// <param name="keys">Keys to be watched</param> |
| | | 427 | | /// <param name="method">Method to which minimal watch events data should be passed on</param> |
| | | 428 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 429 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 430 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 431 | | public void Watch(string[] keys, Action<WatchEvent[]> method, Metadata headers = null, |
| | | 432 | | DateTime? deadline = null, |
| | 0 | 433 | | CancellationToken cancellationToken = default) => Watch(keys, [method], headers, |
| | 0 | 434 | | deadline, cancellationToken); |
| | | 435 | | |
| | | 436 | | /// <summary> |
| | | 437 | | /// Watches the specified keys and passes the minimal watch events data to the method provided. |
| | | 438 | | /// </summary> |
| | | 439 | | /// <param name="keys">Keys to be watched</param> |
| | | 440 | | /// <param name="methods">Methods to which minimal watch events data should be passed on</param> |
| | | 441 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 442 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 443 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 444 | | public void Watch(string[] keys, Action<WatchEvent[]>[] methods, Metadata headers = null, |
| | | 445 | | DateTime? deadline = null, |
| | | 446 | | CancellationToken cancellationToken = default) |
| | 0 | 447 | | { |
| | 0 | 448 | | List<WatchRequest> requests = []; |
| | | 449 | | |
| | 0 | 450 | | foreach (string key in keys) |
| | 0 | 451 | | { |
| | 0 | 452 | | WatchRequest request = new() |
| | 0 | 453 | | { |
| | 0 | 454 | | CreateRequest = new WatchCreateRequest { Key = ByteString.CopyFromUtf8(key) } |
| | 0 | 455 | | }; |
| | 0 | 456 | | requests.Add(request); |
| | 0 | 457 | | } |
| | | 458 | | |
| | 0 | 459 | | Watch(requests.ToArray(), methods, headers, deadline, cancellationToken); |
| | 0 | 460 | | } |
| | | 461 | | |
| | | 462 | | |
| | | 463 | | /// <summary> |
| | | 464 | | /// Watches the specified key and passes the watch response to the method provided. |
| | | 465 | | /// </summary> |
| | | 466 | | /// <param name="key">Key to be watched</param> |
| | | 467 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 468 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 469 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 470 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 471 | | public Task WatchAsync(string key, Action<WatchResponse> method, Metadata headers = null, |
| | | 472 | | DateTime? deadline = null, |
| | 0 | 473 | | CancellationToken cancellationToken = default) => WatchAsync([key], |
| | 0 | 474 | | [method], headers, deadline, cancellationToken); |
| | | 475 | | |
| | | 476 | | /// <summary> |
| | | 477 | | /// Watches the specified key and passes the watch response to the methods provided. |
| | | 478 | | /// </summary> |
| | | 479 | | /// <param name="key">Key to be watched</param> |
| | | 480 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 481 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 482 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 483 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 484 | | public Task WatchAsync(string key, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 485 | | DateTime? deadline = null, |
| | | 486 | | CancellationToken cancellationToken = default) => |
| | 0 | 487 | | WatchAsync([key], methods, headers, deadline, cancellationToken); |
| | | 488 | | |
| | | 489 | | |
| | | 490 | | /// <summary> |
| | | 491 | | /// Watches the specified keys and passes the watch response to the method provided. |
| | | 492 | | /// </summary> |
| | | 493 | | /// <param name="keys">Keys to be watched</param> |
| | | 494 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 495 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 496 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 497 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 498 | | public Task WatchAsync(string[] keys, Action<WatchResponse> method, Metadata headers = null, |
| | | 499 | | DateTime? deadline = null, |
| | 0 | 500 | | CancellationToken cancellationToken = default) => WatchAsync(keys, [method], |
| | 0 | 501 | | headers, deadline, cancellationToken); |
| | | 502 | | |
| | | 503 | | /// <summary> |
| | | 504 | | /// Watches the specified keys and passes the watch response to the method provided. |
| | | 505 | | /// </summary> |
| | | 506 | | /// <param name="keys">Keys to be watched</param> |
| | | 507 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 508 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 509 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 510 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 511 | | public Task WatchAsync(string[] keys, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 512 | | DateTime? deadline = null, |
| | | 513 | | CancellationToken cancellationToken = default) |
| | 0 | 514 | | { |
| | 0 | 515 | | List<WatchRequest> requests = []; |
| | | 516 | | |
| | 0 | 517 | | foreach (string key in keys) |
| | 0 | 518 | | { |
| | 0 | 519 | | WatchRequest request = new() |
| | 0 | 520 | | { |
| | 0 | 521 | | CreateRequest = new WatchCreateRequest |
| | 0 | 522 | | { |
| | 0 | 523 | | Key = ByteString.CopyFromUtf8(key), ProgressNotify = true, PrevKv = true |
| | 0 | 524 | | } |
| | 0 | 525 | | }; |
| | 0 | 526 | | requests.Add(request); |
| | 0 | 527 | | } |
| | | 528 | | |
| | 0 | 529 | | return WatchAsync(requests.ToArray(), methods, headers, deadline, cancellationToken); |
| | 0 | 530 | | } |
| | | 531 | | |
| | | 532 | | /// <summary> |
| | | 533 | | /// Watches the specified key and passes the minimal watch events data to the method provided. |
| | | 534 | | /// </summary> |
| | | 535 | | /// <param name="key">Key to be watched</param> |
| | | 536 | | /// <param name="method">Method to which minimal watch events data should be passed on</param> |
| | | 537 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 538 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 539 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 540 | | public Task WatchAsync(string key, Action<WatchEvent[]> method, Metadata headers = null, |
| | | 541 | | DateTime? deadline = null, |
| | 0 | 542 | | CancellationToken cancellationToken = default) => WatchAsync([key], |
| | 0 | 543 | | [method], headers, deadline, cancellationToken); |
| | | 544 | | |
| | | 545 | | /// <summary> |
| | | 546 | | /// Watches the specified key and passes the minimal watch events data to the methods provided. |
| | | 547 | | /// </summary> |
| | | 548 | | /// <param name="key">Key to be watched</param> |
| | | 549 | | /// <param name="methods">Methods to which minimal watch events data should be passed on</param> |
| | | 550 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 551 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 552 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 553 | | public Task WatchAsync(string key, Action<WatchEvent[]>[] methods, Metadata headers = null, |
| | | 554 | | DateTime? deadline = null, |
| | | 555 | | CancellationToken cancellationToken = default) => |
| | 0 | 556 | | WatchAsync([key], methods, headers, deadline, cancellationToken); |
| | | 557 | | |
| | | 558 | | /// <summary> |
| | | 559 | | /// Watches the specified keys and passes the minimal watch events data to the method provided. |
| | | 560 | | /// </summary> |
| | | 561 | | /// <param name="keys">Keys to be watched</param> |
| | | 562 | | /// <param name="method">Method to which minimal watch events data should be passed on</param> |
| | | 563 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 564 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 565 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 566 | | public Task WatchAsync(string[] keys, Action<WatchEvent[]> method, Metadata headers = null, |
| | | 567 | | DateTime? deadline = null, |
| | 0 | 568 | | CancellationToken cancellationToken = default) => WatchAsync(keys, [method], |
| | 0 | 569 | | headers, deadline, cancellationToken); |
| | | 570 | | |
| | | 571 | | /// <summary> |
| | | 572 | | /// Watches the specified keys and passes the minimal watch events data to the method provided. |
| | | 573 | | /// </summary> |
| | | 574 | | /// <param name="keys">Keys to be watched</param> |
| | | 575 | | /// <param name="methods">Methods to which minimal watch events data should be passed on</param> |
| | | 576 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 577 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 578 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 579 | | public Task WatchAsync(string[] keys, Action<WatchEvent[]>[] methods, Metadata headers = null, |
| | | 580 | | DateTime? deadline = null, |
| | | 581 | | CancellationToken cancellationToken = default) |
| | 0 | 582 | | { |
| | 0 | 583 | | List<WatchRequest> requests = []; |
| | | 584 | | |
| | 0 | 585 | | foreach (string key in keys) |
| | 0 | 586 | | { |
| | 0 | 587 | | WatchRequest request = new() |
| | 0 | 588 | | { |
| | 0 | 589 | | CreateRequest = new WatchCreateRequest |
| | 0 | 590 | | { |
| | 0 | 591 | | Key = ByteString.CopyFromUtf8(key), ProgressNotify = true, PrevKv = true |
| | 0 | 592 | | } |
| | 0 | 593 | | }; |
| | 0 | 594 | | requests.Add(request); |
| | 0 | 595 | | } |
| | | 596 | | |
| | 0 | 597 | | return WatchAsync(requests.ToArray(), methods, headers, deadline, cancellationToken); |
| | 0 | 598 | | } |
| | | 599 | | |
| | | 600 | | #endregion |
| | | 601 | | |
| | | 602 | | #region Watch Range of keys |
| | | 603 | | |
| | | 604 | | /// <summary> |
| | | 605 | | /// Watches the specified key range and passes the watch response to the method provided. |
| | | 606 | | /// </summary> |
| | | 607 | | /// <param name="path">Path to be watched</param> |
| | | 608 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 609 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 610 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 611 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 612 | | /// <returns>A watch ID that can be used to cancel the watch</returns> |
| | | 613 | | public long WatchRange(string path, Action<WatchResponse> method, Metadata headers = null, |
| | | 614 | | DateTime? deadline = null, |
| | | 615 | | CancellationToken cancellationToken = default) |
| | 0 | 616 | | { |
| | 0 | 617 | | WatchRequest request = new() |
| | 0 | 618 | | { |
| | 0 | 619 | | CreateRequest = new WatchCreateRequest |
| | 0 | 620 | | { |
| | 0 | 621 | | Key = GetStringByteForRangeRequests(path), |
| | 0 | 622 | | RangeEnd = ByteString.CopyFromUtf8(GetRangeEnd(path)), |
| | 0 | 623 | | ProgressNotify = true, |
| | 0 | 624 | | PrevKv = true |
| | 0 | 625 | | } |
| | 0 | 626 | | }; |
| | | 627 | | |
| | 0 | 628 | | return _watchManager.Watch(request, method, headers, deadline, cancellationToken); |
| | 0 | 629 | | } |
| | | 630 | | |
| | | 631 | | /// <summary> |
| | | 632 | | /// Watches the specified key range and passes the watch response to the methods provided. |
| | | 633 | | /// </summary> |
| | | 634 | | /// <param name="path">Path to be watched</param> |
| | | 635 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 636 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 637 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 638 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 639 | | /// <returns>A watch ID that can be used to cancel the watch</returns> |
| | | 640 | | public long WatchRange(string path, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 641 | | DateTime? deadline = null, |
| | | 642 | | CancellationToken cancellationToken = default) |
| | 0 | 643 | | { |
| | | 644 | | // Create a wrapper method that calls all the methods |
| | 0 | 645 | | Action<WatchResponse> wrapper = response => |
| | 0 | 646 | | { |
| | 0 | 647 | | foreach (Action<WatchResponse> method in methods) |
| | 0 | 648 | | { |
| | 0 | 649 | | method(response); |
| | 0 | 650 | | } |
| | 0 | 651 | | }; |
| | | 652 | | |
| | 0 | 653 | | return WatchRange(path, wrapper, headers, deadline, cancellationToken); |
| | 0 | 654 | | } |
| | | 655 | | |
| | | 656 | | /// <summary> |
| | | 657 | | /// Watches the specified key range and passes the watch response to the method provided. |
| | | 658 | | /// </summary> |
| | | 659 | | /// <param name="paths">Paths to be watched</param> |
| | | 660 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 661 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 662 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 663 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 664 | | /// <returns>An array of watch IDs that can be used to cancel the watches</returns> |
| | | 665 | | public long[] WatchRange(string[] paths, Action<WatchResponse> method, Metadata headers = null, |
| | | 666 | | DateTime? deadline = null, |
| | | 667 | | CancellationToken cancellationToken = default) |
| | 0 | 668 | | { |
| | 0 | 669 | | long[] watchIds = new long[paths.Length]; |
| | | 670 | | |
| | 0 | 671 | | for (int i = 0; i < paths.Length; i++) |
| | 0 | 672 | | { |
| | 0 | 673 | | watchIds[i] = WatchRange(paths[i], method, headers, deadline, cancellationToken); |
| | 0 | 674 | | } |
| | | 675 | | |
| | 0 | 676 | | return watchIds; |
| | 0 | 677 | | } |
| | | 678 | | |
| | | 679 | | /// <summary> |
| | | 680 | | /// Watches the specified key range and passes the watch response to the method provided. |
| | | 681 | | /// </summary> |
| | | 682 | | /// <param name="paths">Paths to be watched</param> |
| | | 683 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 684 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 685 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 686 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 687 | | /// <returns>An array of watch IDs that can be used to cancel the watches</returns> |
| | | 688 | | public long[] WatchRange(string[] paths, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 689 | | DateTime? deadline = null, |
| | | 690 | | CancellationToken cancellationToken = default) |
| | 0 | 691 | | { |
| | 0 | 692 | | if (paths.Length != methods.Length) |
| | 0 | 693 | | { |
| | 0 | 694 | | throw new ArgumentException("The number of paths must match the number of methods"); |
| | | 695 | | } |
| | | 696 | | |
| | 0 | 697 | | long[] watchIds = new long[paths.Length]; |
| | | 698 | | |
| | 0 | 699 | | for (int i = 0; i < paths.Length; i++) |
| | 0 | 700 | | { |
| | 0 | 701 | | watchIds[i] = WatchRange(paths[i], methods[i], headers, deadline, cancellationToken); |
| | 0 | 702 | | } |
| | | 703 | | |
| | 0 | 704 | | return watchIds; |
| | 0 | 705 | | } |
| | | 706 | | |
| | | 707 | | /// <summary> |
| | | 708 | | /// Watches the specified key range and passes the watch response to the method provided asynchronously. |
| | | 709 | | /// </summary> |
| | | 710 | | /// <param name="path">Path to be watched</param> |
| | | 711 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 712 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 713 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 714 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 715 | | /// <returns>A task that completes with the watch ID</returns> |
| | | 716 | | public Task<long> WatchRangeAsync(string path, Action<WatchResponse> method, Metadata headers = null, |
| | | 717 | | DateTime? deadline = null, |
| | | 718 | | CancellationToken cancellationToken = default) |
| | 0 | 719 | | { |
| | 0 | 720 | | WatchRequest request = new() |
| | 0 | 721 | | { |
| | 0 | 722 | | CreateRequest = new WatchCreateRequest |
| | 0 | 723 | | { |
| | 0 | 724 | | Key = GetStringByteForRangeRequests(path), |
| | 0 | 725 | | RangeEnd = ByteString.CopyFromUtf8(GetRangeEnd(path)), |
| | 0 | 726 | | ProgressNotify = true, |
| | 0 | 727 | | PrevKv = true |
| | 0 | 728 | | } |
| | 0 | 729 | | }; |
| | | 730 | | |
| | 0 | 731 | | return _watchManager.WatchAsync(request, method, headers, deadline, cancellationToken); |
| | 0 | 732 | | } |
| | | 733 | | |
| | | 734 | | /// <summary> |
| | | 735 | | /// Watches the specified key range and passes the watch response to the methods provided asynchronously. |
| | | 736 | | /// </summary> |
| | | 737 | | /// <param name="path">Path to be watched</param> |
| | | 738 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 739 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 740 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 741 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 742 | | /// <returns>A task that completes with the watch ID</returns> |
| | | 743 | | public Task<long> WatchRangeAsync(string path, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 744 | | DateTime? deadline = null, |
| | | 745 | | CancellationToken cancellationToken = default) |
| | 0 | 746 | | { |
| | | 747 | | // Create a wrapper method that calls all the methods |
| | 0 | 748 | | Action<WatchResponse> wrapper = response => |
| | 0 | 749 | | { |
| | 0 | 750 | | foreach (Action<WatchResponse> method in methods) |
| | 0 | 751 | | { |
| | 0 | 752 | | method(response); |
| | 0 | 753 | | } |
| | 0 | 754 | | }; |
| | | 755 | | |
| | 0 | 756 | | return WatchRangeAsync(path, wrapper, headers, deadline, cancellationToken); |
| | 0 | 757 | | } |
| | | 758 | | |
| | | 759 | | /// <summary> |
| | | 760 | | /// Watches the specified key range and passes the watch response to the method provided asynchronously. |
| | | 761 | | /// </summary> |
| | | 762 | | /// <param name="paths">Paths to be watched</param> |
| | | 763 | | /// <param name="method">Method to which a watch response should be passed on</param> |
| | | 764 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 765 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 766 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 767 | | /// <returns>A task that completes with an array of watch IDs</returns> |
| | | 768 | | public async Task<long[]> WatchRangeAsync(string[] paths, Action<WatchResponse> method, Metadata headers = null, |
| | | 769 | | DateTime? deadline = null, |
| | | 770 | | CancellationToken cancellationToken = default) |
| | 0 | 771 | | { |
| | 0 | 772 | | long[] watchIds = new long[paths.Length]; |
| | | 773 | | |
| | 0 | 774 | | for (int i = 0; i < paths.Length; i++) |
| | 0 | 775 | | { |
| | 0 | 776 | | watchIds[i] = await WatchRangeAsync(paths[i], method, headers, deadline, cancellationToken) |
| | 0 | 777 | | .ConfigureAwait(false); |
| | 0 | 778 | | } |
| | | 779 | | |
| | 0 | 780 | | return watchIds; |
| | 0 | 781 | | } |
| | | 782 | | |
| | | 783 | | /// <summary> |
| | | 784 | | /// Watches the specified key range and passes the watch response to the method provided asynchronously. |
| | | 785 | | /// </summary> |
| | | 786 | | /// <param name="paths">Paths to be watched</param> |
| | | 787 | | /// <param name="methods">Methods to which a watch response should be passed on</param> |
| | | 788 | | /// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param> |
| | | 789 | | /// <param name="deadline">An optional deadline for the call. The call will be canceled if the deadline is hit.</par |
| | | 790 | | /// <param name="cancellationToken">An optional token for canceling the call.</param> |
| | | 791 | | /// <returns>A task that completes with an array of watch IDs</returns> |
| | | 792 | | public async Task<long[]> WatchRangeAsync(string[] paths, Action<WatchResponse>[] methods, Metadata headers = null, |
| | | 793 | | DateTime? deadline = null, |
| | | 794 | | CancellationToken cancellationToken = default) |
| | 0 | 795 | | { |
| | 0 | 796 | | if (paths.Length != methods.Length) |
| | 0 | 797 | | { |
| | 0 | 798 | | throw new ArgumentException("The number of paths must match the number of methods"); |
| | | 799 | | } |
| | | 800 | | |
| | 0 | 801 | | long[] watchIds = new long[paths.Length]; |
| | | 802 | | |
| | 0 | 803 | | for (int i = 0; i < paths.Length; i++) |
| | 0 | 804 | | { |
| | 0 | 805 | | watchIds[i] = await WatchRangeAsync(paths[i], methods[i], headers, deadline, cancellationToken) |
| | 0 | 806 | | .ConfigureAwait(false); |
| | 0 | 807 | | } |
| | | 808 | | |
| | 0 | 809 | | return watchIds; |
| | 0 | 810 | | } |
| | | 811 | | |
| | | 812 | | #endregion |
| | | 813 | | } |