All tests passing.

This commit is contained in:
Samuel Guerra 2023-03-29 22:08:51 -03:00
parent 9e701c41ae
commit 0fa96e2075
4 changed files with 36 additions and 20 deletions

View File

@ -1,9 +1,9 @@
error: auto impl delegates call to `update`, but this manual impl does not
`#[deny_(zero_ui::missing_delegate)]` is on
--> cases/ui_node/missing_matching_delegate_child.rs:18:55
--> cases/ui_node/missing_matching_delegate_child.rs:18:51
|
18 | fn update(&mut self, updates: &WidgetUpdates) {
| _______________________________________________________^
| ___________________________________________________^
19 | | let _ = updates;
20 | | // does not call self.child.update(updates);
21 | | }

View File

@ -4,7 +4,7 @@ error: expected square brackets
10 | #![allow(inner_attribute)]
| ^
error: expected path
error: expected identifier
--> cases/widget/malformed_property_attribute.rs:11:11
|
11 | #[!foo]

View File

@ -18,6 +18,7 @@ use std::{mem, thread};
use crate::app::HeadlessApp;
use crate::context::{UPDATES, WIDGET};
use crate::crate_util::{Handle, WeakHandle};
use crate::task;
use crate::task::ui::UiTask;
/// Represents a handler in a widget context.
@ -1708,7 +1709,6 @@ impl HeadlessApp {
if !pending.is_empty() {
let start_time = Instant::now();
#[allow(clippy::blocks_in_if_conditions)] // false positive, see https://github.com/rust-lang/rust-clippy/issues/7580
while {
pending.retain(|h| h());
!pending.is_empty()
@ -1738,26 +1738,38 @@ impl HeadlessApp {
/// Polls a `future` and updates the app repeatedly until it completes or the `timeout` is reached.
pub fn block_on_fut<F: Future>(&mut self, future: F, timeout: Duration) -> Result<F::Output, String> {
let future = task::with_deadline(future, timeout);
let mut future = std::pin::pin!(future);
let waker = UPDATES.waker(vec![]);
let mut cx = std::task::Context::from_waker(&waker);
let start_time = Instant::now();
let mut future = std::pin::pin!(future);
loop {
if start_time.elapsed() >= timeout {
return Err(format!("reached timeout `{timeout:?}`"));
}
match future.as_mut().poll(&mut cx) {
std::task::Poll::Ready(r) => {
return Ok(r);
}
std::task::Poll::Pending => match self.update(false) {
crate::app::ControlFlow::Poll => continue,
crate::app::ControlFlow::Wait => {
thread::yield_now();
continue;
let mut fut_poll = future.as_mut().poll(&mut cx);
let flow = self.update_observe(
|| {
if fut_poll.is_pending() {
fut_poll = future.as_mut().poll(&mut cx);
}
crate::app::ControlFlow::Exit => return Err("app exited".to_owned()),
},
true,
);
match fut_poll {
std::task::Poll::Ready(r) => match r {
Ok(r) => return Ok(r),
Err(e) => return Err(e.to_string()),
},
std::task::Poll::Pending => {}
}
match flow {
crate::app::ControlFlow::Poll => continue,
crate::app::ControlFlow::Wait => {
thread::yield_now();
continue;
}
crate::app::ControlFlow::Exit => return Err("app exited".to_owned()),
}
}
}

View File

@ -595,11 +595,15 @@ where
R: VarValue + Send + 'static,
F: Future<Output = R> + Send + 'static,
{
// !!: replace with var directly
let (sender, response) = response_channel();
spawn(async move {
let r = task.await;
let _ = sender.send_response(r);
match sender.send_response(r) {
Ok(()) => {}
Err(e) => tracing::error!("failed to respond, {e}"),
}
});
response