From cee441bc9af3361b4a70e5e6fd0ed371ce6e37ae Mon Sep 17 00:00:00 2001 From: dnwpark Date: Fri, 10 Jan 2025 19:27:57 -0500 Subject: [PATCH] Use block_on to run query. --- src/connect.rs | 9 +++++++++ src/portable/extension.rs | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/connect.rs b/src/connect.rs index 63c1ab217..a20eeb5f7 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -212,6 +212,15 @@ impl Connector { pub fn get(&self) -> anyhow::Result<&Config, ArcError> { self.config.as_ref().map_err(Clone::clone) } + + pub async fn run_single_query(self, query: &str) -> Result, anyhow::Error> + where + R: QueryResult, + { + let mut connection = self.connect().await?; + let results = connection.query(query, &()).await?; + Ok(results) + } } impl Connection { diff --git a/src/portable/extension.rs b/src/portable/extension.rs index 688fd6784..11096de7f 100644 --- a/src/portable/extension.rs +++ b/src/portable/extension.rs @@ -55,16 +55,6 @@ fn get_local_instance(options: &Options) -> Result Ok(inst) } -#[tokio::main(flavor = "current_thread")] -async fn _run_query(connector: Connector, query: &str) -> Result, anyhow::Error> -where - R: QueryResult, -{ - let mut connection = connector.connect().await?; - let results = connection.query(query, &()).await?; - Ok(results) -} - type ExtensionInfo = (String, String); fn _get_extensions(options: &Options) -> Result, anyhow::Error> { @@ -105,7 +95,16 @@ fn _get_extensions(options: &Options) -> Result, anyhow::Erro );"; let connector = options.block_on_create_connector()?; - _run_query(connector, query) + + let runtime = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()?; + let extension_query = runtime.spawn( + connector.run_single_query::(query) + ); + + let extensions = runtime.block_on(extension_query)??; + Ok(extensions) } fn list(_: &ExtensionList, options: &Options) -> Result<(), anyhow::Error> {