about summary refs log tree commit diff
path: root/tvix/build/src/buildservice/grpc.rs
blob: 9d22d8397abffc0febb7e41b539af35a539a02aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use tonic::{async_trait, transport::Channel};

use crate::proto::{build_service_client::BuildServiceClient, Build, BuildRequest};

use super::BuildService;

pub struct GRPCBuildService {
    client: BuildServiceClient<Channel>,
}

impl GRPCBuildService {
    #[allow(dead_code)]
    pub fn from_client(client: BuildServiceClient<Channel>) -> Self {
        Self { client }
    }
}

#[async_trait]
impl BuildService for GRPCBuildService {
    async fn do_build(&self, request: BuildRequest) -> std::io::Result<Build> {
        let mut client = self.client.clone();
        client
            .do_build(request)
            .await
            .map(|resp| resp.into_inner())
            .map_err(std::io::Error::other)
    }
}