 joinClientRWOp act = do
   x <- clientRWOp act
   joinReply x
-
 
 branchOnStatus :: Rpc req resp a
                -> Rpc req resp a

      | code == StatusOk -> onSuccess
      | otherwise -> onFail code msg

abortIfStatus :: Rpc req resp ()
abortIfStatus =
  branchOnStatus
    (return ())
    (return ())


withClient :: Client req resp -> Rpc req resp a -> IO (RpcReply a)
withClient client m = do
  let m' = do
        x <- m
        _ <- waitForStatus
        throwIfErrorStatus
        return x
  e <- runExceptT (runReaderT m' client)
  case e of
    Left err -> return (RpcError err)
    Right a -> return (RpcOk a)
