| 55 | |
| 56 | impl ReviewImpl { |
| 57 | async fn run<T: Send + 'static>( |
| 58 | &self, |
| 59 | reference: Option<RepositoryRef>, |
| 60 | method: &'static str, |
| 61 | write: bool, |
| 62 | action: impl FnOnce(&Repository) -> Result<T, Status> + Send + 'static, |
| 63 | ) -> Result<Response<T>, Status> { |
| 64 | let reference = reference |
| 65 | .ok_or_else(|| Status::invalid_argument("repository reference is required"))?; |
| 66 | let handle = self.state.resolve(&reference)?; |
| 67 | self.state.log_rpc(method, Some(&handle)); |
| 68 | let guard = handle.exclusive_owned().await; |
| 69 | tokio::task::spawn_blocking(move || { |
| 70 | // A cancelled client cannot release repository exclusion while the |
| 71 | // blocking operation is still executing or materializing effects. |
| 72 | let _guard = guard; |
| 73 | let repo = if write { |
| 74 | handle.repository()? |
| 75 | } else { |
| 76 | handle.repository_readonly()? |
| 77 | }; |
| 78 | action(&repo) |
| 79 | }) |
| 80 | .await |
| 81 | .map_err(|error| Status::internal(error.to_string()))? |
| 82 | .map(Response::new) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | #[tonic::async_trait] |