Skip to content
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

Use run() instead of tick() #697

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions zbus/src/connection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,35 @@ impl<'a> Builder<'a> {
/// tasks until socket reader task kicks in.
#[cfg(not(feature = "tokio"))]
fn start_internal_executor(executor: &Executor<'static>, internal_executor: bool) -> Result<()> {
use core::{
future::Future,
pin::Pin,
task::{Context, Poll},
};

/// A future that ends once the executor is empty.
struct Empty<'a>(&'a Executor<'static>);

impl Future for Empty<'_> {
type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.0.is_empty() {
Poll::Ready(())
} else {
Poll::Pending
}
}
}

if internal_executor {
let executor = executor.clone();
std::thread::Builder::new()
.name("zbus::Connection executor".into())
.spawn(move || {
crate::utils::block_on(async move {
// Run as long as there is a task to run.
while !executor.is_empty() {
executor.tick().await;
}
executor.run(Empty(&executor)).await
Copy link
Contributor

@zeenix zeenix Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executor running a dummy future, to run itself seems very weird. I understood from your comment here that you intend to make tick also more efficient, so maybe we just wait for that? It all depends on how much efficiency and under which scenarios would it be significant enough to justify sacrificing code readability and many Future impls.

})
})?;
}
Expand Down