MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / blocking_complete

Function blocking_complete

crates/openshell-cli/src/completers.rs:138–153  ·  view source on GitHub ↗

Run an async future on a dedicated thread to avoid nested tokio runtime panics. `#[tokio::main]` creates a runtime, and `CompleteEnv::complete()` runs synchronously inside its `block_on`. Creating another runtime on the same thread would panic, so we spawn a new OS thread with its own single-threaded runtime.

(future: F)

Source from the content-addressed store, hash-verified

136/// inside its `block_on`. Creating another runtime on the same thread would panic, so
137/// we spawn a new OS thread with its own single-threaded runtime.
138fn blocking_complete<F>(future: F) -> Vec<CompletionCandidate>
139where
140 F: Future<Output = Option<Vec<CompletionCandidate>>> + Send + 'static,
141{
142 std::thread::spawn(move || {
143 let rt = tokio::runtime::Builder::new_current_thread()
144 .enable_all()
145 .build()
146 .ok()?;
147 rt.block_on(future)
148 })
149 .join()
150 .ok()
151 .flatten()
152 .unwrap_or_default()
153}
154
155#[cfg(test)]
156mod tests {

Callers 2

complete_sandbox_namesFunction · 0.85
complete_provider_namesFunction · 0.85

Calls 2

spawnFunction · 0.50
buildMethod · 0.45

Tested by

no test coverage detected