public Task Disconnect()
        {
            var tcs = new TaskCompletionSource <bool>();

            _pipeline.CloseConnection(
                ex =>
            {
                _state = ClientState.Disconnect;
                if (ex != null)
                {
                    tcs.SetException(ProcessException(ex));
                }
                else
                {
                    tcs.SetResult(true);
                }
            });
            return(tcs.Task);
        }