public void WaitForCompletionResponseAsyncCancelled() { var cts = new CancellationTokenSource(); var poller = new OperationPoller(new TestDelayStrategy(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1), cts)); var operation = new OperationInternal(new ClientDiagnostics(ClientOptions.Default), new EndlessOperation(), new MockResponse(200)); Assert.CatchAsync <OperationCanceledException>(async() => await poller.WaitForCompletionResponseAsync(operation, null, cts.Token)); }
/// <summary> /// Periodically calls the server till the long-running operation completes. /// </summary> /// <param name="pollingInterval"> /// The interval between status requests to the server. /// The interval can change based on information returned from the server. /// For example, the server might communicate to the client that there is not reason to poll for status change sooner than some time. /// </param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> used for the periodical service calls.</param> /// <returns>The last HTTP response received from the server.</returns> /// <remarks> /// This method will periodically call UpdateStatusAsync till HasCompleted is true, then return the final response of the operation. /// </remarks> public virtual async ValueTask <Response> WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) { OperationPoller poller = new OperationPoller(); return(await poller.WaitForCompletionResponseAsync(this, pollingInterval, cancellationToken).ConfigureAwait(false)); }