These helpers work around DataFusion FFI callbacks that may run without an entered Tokio runtime. See https://github.com/apache/datafusion/issues/16312. A global OnceLock avoids creating a new runtime on every call; if DataFusion fixes runtime propagation end-to-end, we should be able to remove these manual fallback runtimes.
(future: F)
| 46 | // if DataFusion fixes runtime propagation end-to-end, we should be able to |
| 47 | // remove these manual fallback runtimes. |
| 48 | pub(crate) async fn await_with_runtime<F>(future: F) -> F::Output |
| 49 | where |
| 50 | F: Future, |
| 51 | { |
| 52 | if Handle::try_current().is_ok() { |
| 53 | future.await |
| 54 | } else { |
| 55 | global_runtime().block_on(future) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // The blocking variant is for synchronous DataFusion FFI callbacks such as |
| 60 | // CatalogProvider::schema(), where we cannot `.await` directly. |