         RpcError err ->
           return (RpcError err)
 
-clientReadInitialMetadata :: ClientReaderWriter -> IO (RpcReply (Maybe [Metadata]))
-clientReadInitialMetadata (ClientReaderWriter {..}) = do
-  md <- readIORef initialMDRef
-  return (RpcOk md)
-
 clientRead :: ClientReaderWriter -> IO (RpcReply (Maybe L.ByteString))
 clientRead crw = do
   _ <- clientWaitForInitialMetadata crw

        RpcError err -> return (RpcError err)

callBidi :: ClientContext -> CallOptions -> MethodName -> IO (RpcReply (Client B.ByteString L.ByteString))
callBidi ctx@(ClientContext chan cq _) co method = do
  deadline <- resolveDeadline co
  mcall <- grpcChannelCreateCall (cChannel chan) C.nullPtr propagateDefaults cq method (cHost chan) deadline >>= newMVar

  crw <- newClientReaderWriter ctx mcall
  let client = Client crw defaultEncoder defaultDecoder

  return (ClientContext chan cq cqt)

destroyClientContext :: ClientContext -> IO ()
destroyClientContext ClientContext{ccCQ, ccWorker} = do
  completionQueueShutdown ccCQ
  CQ.waitWorkerTermination ccWorker

type MethodName = Slice
type Arg = B.ByteString

reservedPtr :: Ptr ()
reservedPtr = C.nullPtr

data UnaryResult a = UnaryResult [Metadata] [Metadata] a deriving Show

callUnary :: ClientContext -> CallOptions -> MethodName -> Arg -> IO (RpcReply (UnaryResult L.ByteString))
callUnary ctx@ClientContext{ccChannel, ccCQ} co method arg = do
  deadline <- resolveDeadline co
  bracket (grpcChannelCreateCall (cChannel ccChannel) C.nullPtr propagateDefaults ccCQ method (cHost ccChannel) deadline) grpcCallUnref $ \call0 -> newMVar call0 >>= \mcall -> do
    crw <- newClientReaderWriter ctx mcall

    sendInitOp <- opSendInitialMetadata (metadataToSend co)
