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