protected override Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback) #endif { #if ASYNC Task <T> operationTask = asyncOperationCallback.Task; Task <Exception> disconnectionTask = mDisconnectionTaskCompletionSource.Task; Task task = await Task.WhenAny(operationTask, disconnectionTask) .ConfigureAwait(false); if (!operationTask.IsCompleted) { Exception exception = await disconnectionTask.ConfigureAwait(false); asyncOperationCallback.SetException(exception); } T result = await operationTask.ConfigureAwait(false); return(result); #else IObservable <T> merged = Observable.Amb (asyncOperationCallback.Task.ToObservable(), mDisconnectionTaskCompletionSource.Task.ToObservable() .SelectMany(x => Observable.Throw <T>(x))); Task <T> task = merged.ToTask(); return(task); #endif }
public Task <T> InvokeAsync <T>(ICalleeProxyInterceptor interceptor, MethodInfo method, IOperationResultExtractor <T> extractor, object[] arguments) { AsyncOperationCallback <T> callback = new AsyncOperationCallback <T>(extractor); Task <T> task = InnerInvokeAsync <T>(callback, interceptor, method, arguments); return(task); }
private Task <T> InnerInvokeAsync <T>(AsyncOperationCallback <T> callback, ICalleeProxyInterceptor interceptor, MethodInfo method, object[] arguments, CancellationToken cancellationToken) { var cancellableInvocation = Invoke(interceptor, callback, method, arguments); // TODO: make the CancelOptions come from the ICalleeProxyInterceptor or something. CancellationTokenRegistration registration = cancellationToken.Register(() => cancellableInvocation.Cancel(new CancelOptions())); return(AwaitForResult(callback, registration)); }
protected override Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback) #endif { #if NET45 Task <T> operationTask = asyncOperationCallback.Task; Task task = await Task.WhenAny(operationTask, mDisconnectionTaskCompletionSource.Task) .ConfigureAwait(false); T result = await operationTask.ConfigureAwait(false); return(result); #else IObservable <T> merged = Observable.Amb(asyncOperationCallback.Task.ToObservable(), mDisconnectionTaskCompletionSource.Task.ToObservable().Cast <T>()); Task <T> task = merged.ToTask(); return(task); #endif }
protected override async Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback, CancellationTokenRegistration registration) { Task <T> operationTask = asyncOperationCallback.Task; Task <Exception> disconnectionTask = mDisconnectionTaskCompletionSource.Task; Task task = await Task.WhenAny(operationTask, disconnectionTask) .ConfigureAwait(false); registration.Dispose(); if (!operationTask.IsCompleted) { Exception exception = await disconnectionTask.ConfigureAwait(false); asyncOperationCallback.SetException(exception); } T result = await operationTask.ConfigureAwait(false); return(result); }
protected override async Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback, CancellationTokenRegistration registration)
protected override async Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback)
protected virtual Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback) { return(asyncOperationCallback.Task); }
private Task <T> InnerInvokeAsync <T>(AsyncOperationCallback <T> callback, ICalleeProxyInterceptor interceptor, MethodInfo method, object[] arguments) { Invoke(interceptor, callback, method, arguments); return(AwaitForResult(callback)); }
protected virtual Task <T> AwaitForResult <T>(AsyncOperationCallback <T> asyncOperationCallback, CancellationTokenRegistration registration) { return(asyncOperationCallback.Task); }