Run `exchange` against the sandbox's server on a fresh thread and runtime: the link is called synchronously from inside `Repository`, which may itself be running inside an async context (the agent hooks).
(root: &Path, exchange: F)
| 158 | /// runtime: the link is called synchronously from inside `Repository`, which |
| 159 | /// may itself be running inside an async context (the agent hooks). |
| 160 | fn exchange<T, F, Fut>(root: &Path, exchange: F) -> Result<T, String> |
| 161 | where |
| 162 | T: Send + 'static, |
| 163 | F: FnOnce(pb::RepositoryRef, pb::ViewRef, SandboxChannel) -> Fut + Send + 'static, |
| 164 | Fut: std::future::Future<Output = Result<T, String>>, |
| 165 | { |
| 166 | let pointer = RemoteSandboxPointer::read(root) |
| 167 | .ok_or_else(|| format!("{} holds no remote sandbox pointer", root.display()))?; |
| 168 | std::thread::spawn(move || { |
| 169 | let rt = tokio::runtime::Builder::new_current_thread() |
| 170 | .enable_all() |
| 171 | .build() |
| 172 | .map_err(|e| e.to_string())?; |
| 173 | rt.block_on(async move { |
| 174 | let reference = reference(&pointer)?; |
| 175 | let channel = connect(Some(pointer.token.as_bytes())).await?; |
| 176 | exchange(reference, target(&pointer), channel).await |
| 177 | }) |
| 178 | }) |
| 179 | .join() |
| 180 | .map_err(|_| "the sandbox link's thread panicked".to_string())? |
| 181 | } |
| 182 | |
| 183 | fn refused(status: tonic::Status) -> String { |
| 184 | status.message().to_string() |
no test coverage detected