Xuanwo opened a new pull request, #8925:
URL: https://github.com/apache/opendal/pull/8925

   # Which issue does this PR close?
   
   None. Found during maintenance; no separate issue was filed.
   
   # Rationale for this change
   
   `Execute::sleep` returns `Option<BoxedStaticFuture<()>>` so executors can 
signal when timer support is unavailable. While `TokioExecutor::try_execute` 
checks `tokio::runtime::Handle::try_current()` to avoid panicking outside a 
Tokio runtime, `TokioExecutor::sleep` called `tokio::time::sleep` 
unconditionally, causing a synchronous panic (`there is no reactor running, 
must be called from the context of a Tokio 1.x runtime`) whenever called 
outside a Tokio runtime.
   
   # What changes are included in this PR?
   
   - Guard `TokioExecutor::sleep` with 
`tokio::runtime::Handle::try_current().ok()?;` so it returns `None` instead of 
panicking when no Tokio runtime is active on the current thread.
   - Document this behavior on `TokioExecutor`.
   - Add unit tests verifying `TokioExecutor::sleep` returns `None` outside a 
Tokio runtime and returns a completing timer future inside a Tokio runtime.
   
   Note: Tokio 1.x does not provide a public non-panicking API to check whether 
the time driver is enabled on an active runtime; if a runtime is constructed 
without `.enable_time()`, `tokio::time::sleep` still panics.
   
   # Are there any user-facing changes?
   
   Calling `TokioExecutor::sleep` outside a Tokio runtime now returns `None` 
instead of panicking.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Reproduced the panic outside a Tokio runtime, added the 
`Handle::try_current()` guard, updated rustdoc, and added unit tests. Note that 
Tokio 1.x exposes no public non-panicking probe for whether a runtime enabled 
its time driver, so this guard only covers calls outside an active Tokio 
runtime.


-- 
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