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); }
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)); } }
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); }
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); } }
private void SetException(object state) => _tcs.TrySetException((Exception)state);