v0y4g3r commented on issue #3777:
URL: 
https://github.com/apache/arrow-datafusion/issues/3777#issuecomment-1309694046

   > I would also be interested in this in this feature. I tried using 
`futures::executor::block_on` but this leads to my execution hanging as 
described in 
[tokio-rs/tokio#2376](https://github.com/tokio-rs/tokio/issues/2376).
   
   I found a workaround. In this case you can spawn a thread dedicating to 
block:
   ```rust
   use std::collections::HashMap;
   use std::sync::Arc;
   use tokio::sync::RwLock;
   
   trait CatalogList {
       fn catalog(&self, name: &str) -> Option<Arc<CatalogProvider>>;
   }
   
   struct CatalogProvider;
   
   #[derive(Default)]
   struct CatalogListImpl {
       map: Arc<RwLock<HashMap<String, Arc<CatalogProvider>>>>,
   }
   
   impl CatalogList for CatalogListImpl {
       fn catalog(&self, name: &str) -> Option<Arc<CatalogProvider>> {
           let map = self.map.clone();
           let name = name.to_string();
           std::thread::spawn(move || {
               futures::executor::block_on(async {
                   map.read().await.get(&name).cloned()
               })
           }).join().unwrap()
       }
   }
   
   #[tokio::main]
   async fn main() {
       let catalog_list = CatalogListImpl::default();
       assert!(catalog_list.catalog("hello").is_none());
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to