2023-09-04 02:30:47 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use tokio::sync::{Notify, Semaphore};
|
|
|
|
|
2023-09-11 00:43:51 +00:00
|
|
|
#[track_caller]
|
2023-09-04 02:30:47 +00:00
|
|
|
pub(crate) fn channel<T>(bound: usize) -> (flume::Sender<T>, flume::Receiver<T>) {
|
|
|
|
tracing::trace_span!(parent: None, "make channel").in_scope(|| flume::bounded(bound))
|
|
|
|
}
|
|
|
|
|
2023-09-11 00:43:51 +00:00
|
|
|
#[track_caller]
|
2023-09-04 02:30:47 +00:00
|
|
|
pub(crate) fn notify() -> Arc<Notify> {
|
|
|
|
Arc::new(bare_notify())
|
|
|
|
}
|
|
|
|
|
2023-09-11 00:43:51 +00:00
|
|
|
#[track_caller]
|
2023-09-04 02:30:47 +00:00
|
|
|
pub(crate) fn bare_notify() -> Notify {
|
|
|
|
tracing::trace_span!(parent: None, "make notifier").in_scope(Notify::new)
|
|
|
|
}
|
|
|
|
|
2023-09-11 00:43:51 +00:00
|
|
|
#[track_caller]
|
2023-09-04 02:30:47 +00:00
|
|
|
pub(crate) fn bare_semaphore(permits: usize) -> Semaphore {
|
|
|
|
tracing::trace_span!(parent: None, "make semaphore").in_scope(|| Semaphore::new(permits))
|
|
|
|
}
|
|
|
|
|
2023-09-11 00:43:51 +00:00
|
|
|
#[track_caller]
|
2023-09-04 02:30:47 +00:00
|
|
|
pub(crate) fn spawn<F>(future: F) -> actix_rt::task::JoinHandle<F::Output>
|
|
|
|
where
|
|
|
|
F: std::future::Future + 'static,
|
|
|
|
F::Output: 'static,
|
|
|
|
{
|
|
|
|
tracing::trace_span!(parent: None, "spawn task").in_scope(|| actix_rt::spawn(future))
|
|
|
|
}
|
|
|
|
|
2023-09-11 00:43:51 +00:00
|
|
|
#[track_caller]
|
2023-09-04 02:30:47 +00:00
|
|
|
pub(crate) fn spawn_blocking<F, Out>(function: F) -> actix_rt::task::JoinHandle<Out>
|
|
|
|
where
|
|
|
|
F: FnOnce() -> Out + Send + 'static,
|
|
|
|
Out: Send + 'static,
|
|
|
|
{
|
|
|
|
let outer_span = tracing::Span::current();
|
|
|
|
|
|
|
|
tracing::trace_span!(parent: None, "spawn blocking task")
|
|
|
|
.in_scope(|| actix_rt::task::spawn_blocking(move || outer_span.in_scope(function)))
|
|
|
|
}
|