mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-16 00:00:12 +02:00
A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The executor implementation is now provided by the main `tokio` crate. Functionality can be opted out of by using the various net related feature flags.
37 lines
950 B
Rust
37 lines
950 B
Rust
use crate::executor::loom::sync::Arc;
|
|
use crate::executor::task::Task;
|
|
use crate::executor::thread_pool::queue::Cluster;
|
|
|
|
pub(crate) struct Inject<T: 'static> {
|
|
cluster: Arc<Cluster<T>>,
|
|
}
|
|
|
|
impl<T: 'static> Inject<T> {
|
|
pub(super) fn new(cluster: Arc<Cluster<T>>) -> Inject<T> {
|
|
Inject { cluster }
|
|
}
|
|
|
|
/// Push a value onto the queue
|
|
pub(crate) fn push<F>(&self, task: Task<T>, f: F)
|
|
where
|
|
F: FnOnce(Result<(), Task<T>>),
|
|
{
|
|
self.cluster.global.push(task, f)
|
|
}
|
|
|
|
/// Close the queue
|
|
///
|
|
/// Returns `true` if the channel was closed. `false` indicates the pool was
|
|
/// previously closed.
|
|
pub(crate) fn close(&self) -> bool {
|
|
self.cluster.global.close()
|
|
}
|
|
|
|
/// Wait for all locks on the queue to drop.
|
|
///
|
|
/// This is done by locking w/o doing anything.
|
|
pub(crate) fn wait_for_unlocked(&self) {
|
|
self.cluster.global.wait_for_unlocked();
|
|
}
|
|
}
|