jorgehermo9 opened a new issue, #5857:
URL: https://github.com/apache/opendal/issues/5857

   While working on https://github.com/apache/opendal/issues/5678 I had the 
necessity of calling an `async` function within a sync function.
   
   I saw the `BlockingLayer` did something very similar of what I wanted in 
those two lines:
   
   
https://github.com/apache/opendal/blob/fc767b24bf2a9bbef59dd3978a9e20583bbde2dd/core/src/layers/blocking.rs#L137
   
   and
   
   
https://github.com/apache/opendal/blob/fc767b24bf2a9bbef59dd3978a9e20583bbde2dd/core/src/layers/blocking.rs#L232
   
   However, when I tried the following `BlockingLayer` example at 
https://github.com/apache/opendal/blob/fc767b24bf2a9bbef59dd3978a9e20583bbde2dd/core/src/layers/blocking.rs#L43
   
   with the following main code based on that example:
   
   ```rust
   #[tokio::main]
   async fn main() -> Result<()> {
       // Create fs backend builder.
   
       // Build an `BlockingOperator` with blocking layer to start operating 
the storage.
       let op: BlockingOperator = Operator::new(services::Memory::default())?
           .layer(BlockingLayer::create()?)
           .finish()
           .blocking();
       op.write("test", "content")?;
       Ok(())
   }
   ```
   
   It panicked with the following error: 
   ```console
   thread 'main' panicked at 
/home/jorge/github/opendal/core/src/layers/blocking.rs:232:21:
   Cannot start a runtime from within a runtime. This happens because a 
function (like `block_on`) attempted to block the current thread while the 
thread is being used to drive asynchronous tasks.
   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
   ```
   
   It seems that using `Handle::current().block_on(..)` does not work propertly 
within async contexts... Or am I doing something wrong? 
   
   I am trying to do something very similar at 
https://github.com/apache/opendal/issues/5678 and I wonder what should be the 
correct approach in these cases


-- 
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: commits-unsubscr...@opendal.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to