MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / exchange

Function exchange

atomic-cli/src/remote_sandbox.rs:160–181  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

158/// runtime: the link is called synchronously from inside `Repository`, which
159/// may itself be running inside an async context (the agent hooks).
160fn exchange<T, F, Fut>(root: &Path, exchange: F) -> Result<T, String>
161where
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
183fn refused(status: tonic::Status) -> String {
184 status.message().to_string()

Callers 6

file_statesMethod · 0.85
submitMethod · 0.85
changesMethod · 0.85
publish_provenanceMethod · 0.85
submit_attestationMethod · 0.85
callMethod · 0.85

Calls 6

referenceFunction · 0.85
connectFunction · 0.70
targetFunction · 0.70
readFunction · 0.50
buildMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected