public async Task ShouldDisposeOfSemaphoreSlim(SemaphoreSlimLock sut) { sut.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>( () => GetSemaphore(sut).WaitAsync()); }
public async Task ReleaseAsync_ShouldThrowIfDisposed(SemaphoreSlimLock sut) { sut.Dispose(); var exception = await AssertThrowsAsync <ObjectDisposedException>( () => sut.ReleaseAsync(Cts.Token)); Assert.Equal(typeof(SemaphoreSlimLock).FullName, exception.ObjectName); }
public async ValueTask <ConnectionWithDisconnect> ConnectAsync(CancellationToken cancellationToken) { var client = new TcpClient(); await client.ConnectAsync(_host, _port, cancellationToken).ConfigureAwait(false); var stream = client.GetStream(); var sendLock = new SemaphoreSlimLock(); var receiveLock = new SemaphoreSlimLock(); var connection = _factory.CreateProtobufConnection(stream) .WithLocking(sendLock, receiveLock); return(new ConnectionWithDisconnect(connection, async() => { receiveLock.Dispose(); sendLock.Dispose(); stream.Close(); await stream.DisposeAsync().ConfigureAwait(false); client.Dispose(); })); }
public void Dispose() { readLock.Dispose(); }
public void Dispose() { tcpStream.Dispose(); tcpClient.Dispose(); readLock.Dispose(); }
/// <summary> /// Clean up the lock. /// </summary> public void Dispose() { locker.Dispose(); }