use std::{future::Future, task::Poll};
use tokio::task::JoinHandle;
mod state;
mod subscriber;
mod task;
use subscriber::run_test;
pub(crate) use subscriber::MAIN_TASK_NAME;
pub(crate) use task::ExpectedTask;
#[track_caller]
#[allow(dead_code)]
pub(crate) fn assert_task<Fut>(expected_task: ExpectedTask, future: Fut)
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
run_test(vec![expected_task], future)
}
#[track_caller]
#[allow(dead_code)]
pub(crate) fn assert_tasks<Fut>(expected_tasks: Vec<ExpectedTask>, future: Fut)
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
run_test(expected_tasks, future)
}
#[allow(dead_code)]
pub(crate) fn spawn_named<Fut>(name: &str, f: Fut) -> JoinHandle<<Fut as Future>::Output>
where
Fut: Future + Send + 'static,
Fut::Output: Send + 'static,
{
tokio::task::Builder::new()
.name(name)
.spawn(f)
.unwrap_or_else(|_| panic!("spawning task '{name}' failed"))
}
#[allow(dead_code)]
pub(crate) fn self_wake() -> impl Future<Output = ()> {
struct SelfWake {
yielded: bool,
}
impl Future for SelfWake {
type Output = ();
fn poll(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> Poll<Self::Output> {
if self.yielded {
return Poll::Ready(());
}
self.yielded = true;
cx.waker().wake_by_ref();
Poll::Pending
}
}
SelfWake { yielded: false }
}