CTTY commented on code in PR #2308:
URL: https://github.com/apache/iceberg-rust/pull/2308#discussion_r3165022363
##########
crates/iceberg/src/runtime/mod.rs:
##########
@@ -39,37 +43,245 @@ impl<T: Send + 'static> Future for JoinHandle<T> {
}
}
-#[allow(dead_code)]
-pub fn spawn<F>(f: F) -> JoinHandle<F::Output>
-where
- F: std::future::Future + Send + 'static,
- F::Output: Send + 'static,
-{
- JoinHandle(task::spawn(f))
+/// Handle to a single tokio runtime. Holds an optional `Arc` to keep the
+/// runtime alive when we own it, and a `Handle` for spawning.
+#[derive(Clone)]
+pub struct RuntimeHandle {
+ /// Keeps the tokio runtime alive when we own it (`Runtime::new`).
+ /// `None` when borrowing an existing runtime via `Handle::try_current()`.
+ _owned: Option<Arc<tokio::runtime::Runtime>>,
Review Comment:
tokio won't guarantee the handle to complete if the runtime was dropped:
https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html#:~:text=Shutting%20down%20the,yield%20until%20completion.
##########
crates/iceberg/src/runtime/mod.rs:
##########
@@ -17,12 +17,16 @@
// This module contains the async runtime abstraction for iceberg.
+use std::fmt;
use std::future::Future;
use std::pin::Pin;
+use std::sync::Arc;
use std::task::{Context, Poll};
use tokio::task;
+use tracing::warn;
+/// Wrapper around tokio's JoinHandle that panics on task failure.
pub struct JoinHandle<T>(task::JoinHandle<T>);
Review Comment:
The error handling would be rather painful. tokio's JoinHandle's Output is
`Result<tokio's T, JoinError>`:
https://github.com/tokio-rs/tokio/blob/master/tokio/src/runtime/task/join.rs#L325
without the wrapper, we will need to handle the JoinError directly
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]