Ejemplo n.º 1
0
        public void TrySetException() {
            var tcs = new TaskCompletionSourceEx<int>();
            var count = 0;
            ParallelTools.Invoke(8, i => {
                var isSet = tcs.TrySetException(new Exception());
                if (isSet) {
                    Interlocked.Increment(ref count);
                }
            });

            count.Should().Be(1);
        }
Ejemplo n.º 2
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));
     }
 }
Ejemplo n.º 3
0
        public void TrySetException()
        {
            var tcs   = new TaskCompletionSourceEx <int>();
            var count = 0;

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

            count.Should().Be(1);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
 private void SetException(object state) => _tcs.TrySetException((Exception)state);