Skip to content

Commit

Permalink
Refactor spawn_named to avoid 'unused' warning
Browse files Browse the repository at this point in the history
  • Loading branch information
arqunis committed Sep 27, 2021
1 parent c74162c commit b2197db
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/internal/tokio.rs
@@ -1,13 +1,19 @@
pub fn spawn_named<T>(
name: &str,
future: impl std::future::Future<Output = T> + Send + 'static,
) -> tokio::task::JoinHandle<T>
use std::future::Future;

#[cfg(tokio_unstable)]
pub fn spawn_named<F, T>(name: &str, future: F) -> tokio::task::JoinHandle<T>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
#[cfg(tokio_unstable)]
return tokio::task::Builder::new().name(&*format!("serenity::{}", name)).spawn(future);
tokio::task::Builder::new().name(&*format!("serenity::{}", name)).spawn(future)
}

#[cfg(not(tokio_unstable))]
#[cfg(not(tokio_unstable))]
pub fn spawn_named<F, T>(_name: &str, future: F) -> tokio::task::JoinHandle<T>
where
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
tokio::spawn(future)
}

0 comments on commit b2197db

Please sign in to comment.