Exemplo n.º 1
0
 private static async Task RunHost(RHost host, TaskCompletionSourceEx <object> hostStartedTcs, CancellationToken initializationCt)
 {
     try {
         await host.Run(initializationCt);
     } catch (OperationCanceledException oce) {
         hostStartedTcs.TrySetCanceled(oce);
     } catch (MessageTransportException mte) {
         hostStartedTcs.TrySetCanceled(new RHostDisconnectedException(string.Empty, mte));
     } catch (Exception ex) {
         hostStartedTcs.TrySetException(ex);
     } finally {
         // RHost.Run shouldn't be completed before `IRCallback.Connected` is called
         hostStartedTcs.TrySetCanceled(new RHostDisconnectedException(Resources.Error_UnknownError));
     }
 }
Exemplo n.º 2
0
        private async Task CreateAndRunHost(RHostStartupInfo startupInfo, int timeout)
        {
            try {
                _host = await BrokerConnector.ConnectAsync(startupInfo.Name, this, startupInfo.RHostCommandLineArguments, timeout);

                await _host.Run();
            } catch (OperationCanceledException oce) {
                _initializationTcs.TrySetCanceled(oce);
            } catch (MessageTransportException mte) {
                _initializationTcs.TrySetCanceled(new RHostDisconnectedException(string.Empty, mte));
            } catch (Exception ex) {
                _initializationTcs.TrySetException(ex);
            } finally {
                Interlocked.Exchange(ref _initializationTcs, null);
            }
        }
Exemplo n.º 3
0
        public RSessionRequestSource(bool isVisible, CancellationToken ct) {
            _createRequestTcs = new TaskCompletionSourceEx<IRSessionInteraction>();
            _responseTcs = new TaskCompletionSourceEx<object>();
            _cancellationTokenRegistration = ct.Register(() => _createRequestTcs.TrySetCanceled(cancellationToken:ct));

            IsVisible = isVisible;
        }
Exemplo n.º 4
0
 public RSessionEvaluation(IReadOnlyList <IRContext> contexts, IRExpressionEvaluator evaluator, CancellationToken hostCancellationToken)
 {
     Contexts   = contexts;
     _evaluator = evaluator;
     _tcs       = new TaskCompletionSourceEx <object>();
     _hostCancellationRegistration = hostCancellationToken.Register(() => _tcs.TrySetCanceled(new RHostDisconnectedException()));
 }
Exemplo n.º 5
0
        public RSessionRequestSource(bool isVisible, CancellationToken ct)
        {
            _createRequestTcs = new TaskCompletionSourceEx <IRSessionInteraction>();
            _responseTcs      = new TaskCompletionSourceEx <object>();
            ct.Register(() => _createRequestTcs.TrySetCanceled(cancellationToken: ct));

            IsVisible = isVisible;
        }
Exemplo n.º 6
0
        public Task <REvaluationResult> EvaluateAsync(string expression, REvaluationKind kind, CancellationToken ct)
        {
            if (kind.HasFlag(REvaluationKind.Mutating))
            {
                IsMutating = true;
            }

            ct.Register(() => _tcs.TrySetCanceled());
            return(_evaluator.EvaluateAsync(expression, kind, ct));
        }
Exemplo n.º 7
0
        public void TrySetCanceled() {
            var tcs = new TaskCompletionSourceEx<int>();
            var count = 0;
            ParallelTools.Invoke(8, i => {
                var isSet = tcs.TrySetCanceled();
                if (isSet) {
                    Interlocked.Increment(ref count);
                }
            });

            count.Should().Be(1);
        }
Exemplo n.º 8
0
        public void TrySetCanceled()
        {
            var tcs   = new TaskCompletionSourceEx <int>();
            var count = 0;

            ParallelTools.Invoke(8, i => {
                var isSet = tcs.TrySetCanceled();
                if (isSet)
                {
                    Interlocked.Increment(ref count);
                }
            });

            count.Should().Be(1);
        }
Exemplo n.º 9
0
 private void SetCanceled(object state) => _tcs.TrySetCanceled((OperationCanceledException)state);
Exemplo n.º 10
0
 public void TryCancel(OperationCanceledException exception)
 {
     _createRequestTcs.TrySetCanceled(exception);
     _responseTcs.TrySetCanceled(exception);
 }
Exemplo n.º 11
0
 public bool TryCancel(OperationCanceledException exception)
 {
     return(_tcs.TrySetCanceled(exception));
 }
Exemplo n.º 12
0
 public RSessionEvaluationSource(CancellationToken clientCancellationToken)
 {
     _tcs = new TaskCompletionSourceEx <IRSessionEvaluation>();
     clientCancellationToken.Register(() => _tcs.TrySetCanceled(cancellationToken: clientCancellationToken), false);
 }
Exemplo n.º 13
0
 public void TryCancel(OperationCanceledException exception)
 {
     _createRequestTcs.TrySetCanceled(exception);
     _responseTcs.TrySetCanceled(exception);
     _cancellationTokenRegistration.Dispose();
 }