Havret commented on a change in pull request #18:
URL:
https://github.com/apache/activemq-nms-openwire/pull/18#discussion_r795219887
##########
File path: src/Transport/ResponseCorrelator.cs
##########
@@ -85,15 +87,40 @@ public override FutureResponse AsyncRequest(Command command)
return future;
}
- public override Response Request(Command command, TimeSpan timeout)
+ public override Task<Response> RequestAsync(Command command, TimeSpan
timeout)
{
+ TaskCompletionSource<Response> taskCompletionSource = new
TaskCompletionSource<Response>(TaskCreationOptions.RunContinuationsAsynchronously);
+ if (timeout.TotalMilliseconds > 0)
+ {
+ CancellationTokenSource ct = new
CancellationTokenSource(timeout);
+ ct.Token.Register(() =>
+ {
+ taskCompletionSource.TrySetException(new
RequestTimedOutException(timeout));
+ }, false);
+ }
+
FutureResponse future = AsyncRequest(command);
- future.ResponseTimeout = timeout;
- Response response = future.Response;
- return response;
+
+ _ = future.Task.ContinueWith(t =>
+ {
+ if (t.IsCompleted)
+ {
+ taskCompletionSource.SetResult(t.Result);
+ }
+ else if (t.IsFaulted)
+ {
+ taskCompletionSource.SetException(t.Exception);
+ }
+ else if (t.IsCanceled)
+ {
+ taskCompletionSource.SetCanceled();
+ }
+ });
+
+ return taskCompletionSource.Task;
Review comment:
You should handle scenario when the operation is cancelled and remove
future or TCS from list of pending operations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]