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();
        }));
    }
Exemplo n.º 4
0
 public void Dispose()
 {
     readLock.Dispose();
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     tcpStream.Dispose();
     tcpClient.Dispose();
     readLock.Dispose();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Clean up the lock.
 /// </summary>
 public void Dispose()
 {
     locker.Dispose();
 }