-
-
Notifications
You must be signed in to change notification settings - Fork 99
make the repl tool work with the tokio console #4418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
https://github.com/tokio-rs/console/tree/main this can help with debugging async stuff.
This is very nice, we should merge it in some way. The |
I have created a question about the column meaning at tokio-rs/console#426 |
very cool, agree with @flub s comments |
As this can't be merged, moving it away, still can be found with some effort. |
How about replacing task spawns with a wrapper function like this?: #[inline(always)]
pub fn spawn_named_task<Fut> (name:&str, future: Fut) -> JoinHandle<Fut::Output> where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static, {
#[cfg(tokio_unstable)]
{
tokio::task::Builder::new().name(name)
.spawn(future).expect("Failed to spawn task")
}
#[cfg(not(tokio_unstable))]
{
tokio::task::spawn(future)
}
} Note that it's always in-lined to remove any performance hits when compiling it without the Function with documentation commentdisclaimer: doc comment drafted by gpt4o mini then reviewed and refined by me. /// Spawns a named asynchronous task if the `tokio_unstable` feature is enabled.
///
/// Spawns a new asynchronous task, returning a [JoinHandle] for it.
/// The provided future will start running in the background immediately when spawn is called, even if you don't await the returned JoinHandle.
/// See [tokio::task::spawn].
///
/// If the rustflag `tokio_unstable` is active, the task will be given the specified `name`
/// for easier identification in monitoring tools (like tokio-console).
/// If `tokio_unstable` is not set, the task is spawned normally without a name.
///
/// # Parameters
///
/// - `name`: The name of the task (used only if `tokio_unstable` is enabled).
/// - `future`: The future to be executed, which must implement `Future`, be `Send`, and `'static`.
///
/// # Returns
///
/// A [JoinHandle] that can be awaited to retrieve the output of the future.
///
/// # Panics
///
/// Panics if the task fails to spawn when `tokio_unstable` is enabled.
///
/// # Example
///
/// ```
/// use tokio::task;
///
/// let handle = spawn_named_task("my_task", async {
/// // Your async code here
/// });
///
/// let result = handle.await.unwrap();
/// ```
#[inline(always)]
pub fn spawn_named_task<Fut> (name:&str, future: Fut) -> JoinHandle<Fut::Output> where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static, {
#[cfg(tokio_unstable)]
{
tokio::task::Builder::new().name(name)
.spawn(future).expect("Failed to spawn task")
}
#[cfg(not(tokio_unstable))]
{
tokio::task::spawn(future)
}
} |
I plan on finishing this soon. so reopening. Update: opening failed because |
Seems like we need a macro so the location is also correct in tokio-console: #[macro_export]
macro_rules! spawn_named_task {
($name:expr, $future:expr) => {{
#[inline(always)]
pub fn __spawn_named_task<Fut>(
name: &str,
future: Fut,
) -> ::tokio::task::JoinHandle<Fut::Output>
where
Fut: ::std::future::Future + Send + 'static,
Fut::Output: Send + 'static,
{
#[cfg(tokio_unstable)]
{
::tokio::task::Builder::new()
.name(name)
.spawn(future)
.expect("Failed to spawn task")
}
#[cfg(not(tokio_unstable))]
{
::tokio::task::spawn(future)
}
}
__spawn_named_task($name, $future)
}};
} With docs/// Spawns a named asynchronous task if the `tokio_unstable` feature is enabled.
///
/// Spawns a new asynchronous task, returning a [tokio::task::JoinHandle] for it.
/// The provided future will start running in the background immediately when spawn is called, even if you don't await the returned JoinHandle.
/// See [tokio::task::spawn].
///
/// If the rustflag `tokio_unstable` is active, the task will be given the specified `name`
/// for easier identification in monitoring tools (like tokio-console).
/// If `tokio_unstable` is not set, the task is spawned normally without a name.
///
/// # Parameters
///
/// - `name`: The name of the task (used only if `tokio_unstable` is enabled).
/// - `future`: The future to be executed, which must implement `Future`, be `Send`, and `'static`.
///
/// # Returns
///
/// A [tokio::task::JoinHandle] that can be awaited to retrieve the output of the future.
///
/// # Panics
///
/// Panics if the task fails to spawn when `tokio_unstable` is enabled.
///
/// # Example
///
/// ```
/// use tokio::task;
///
/// let handle = spawn_named_task!("my_task", async {
/// // Your async code here
/// });
///
/// let result = handle.await.unwrap();
/// ```
#[macro_export]
macro_rules! spawn_named_task {
($name:expr, $future:expr) => {{
#[inline(always)]
pub fn __spawn_named_task<Fut>(
name: &str,
future: Fut,
) -> ::tokio::task::JoinHandle<Fut::Output>
where
Fut: ::std::future::Future + Send + 'static,
Fut::Output: Send + 'static,
{
#[cfg(tokio_unstable)]
{
::tokio::task::Builder::new()
.name(name)
.spawn(future)
.expect("Failed to spawn task")
}
#[cfg(not(tokio_unstable))]
{
::tokio::task::spawn(future)
}
}
__spawn_named_task($name, $future)
}};
} |
I think it's ok to recreate the |
I'll make a new pr soon, this pr is already old and probably outdated anyway. |
The new pr: #6018 |
https://github.com/tokio-rs/console/tree/main
this can help with debugging async stuff.
it enables the
tokio_unstable
flag so maybe we can not merge it. but even then we can still rebase and keep this branch up to date and use it for debugging.