Spawn a thread to sleep asynchronously in devtools

... instead of relying on an external reactor.
This commit is contained in:
Héctor Ramón Jiménez 2025-04-05 20:14:51 +02:00
parent 132f60c29c
commit 00ee6ab47a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 15 additions and 7 deletions

1
Cargo.lock generated
View file

@ -2462,7 +2462,6 @@ dependencies = [
"iced_debug", "iced_debug",
"iced_program", "iced_program",
"iced_widget", "iced_widget",
"smol",
] ]
[[package]] [[package]]

View file

@ -17,6 +17,3 @@ workspace = true
iced_program.workspace = true iced_program.workspace = true
iced_widget.workspace = true iced_widget.workspace = true
iced_debug.workspace = true iced_debug.workspace = true
# TODO: Use program executor?
smol.workspace = true

View file

@ -12,11 +12,13 @@ use crate::core::theme::{self, Base, Theme};
use crate::core::time::seconds; use crate::core::time::seconds;
use crate::core::window; use crate::core::window;
use crate::futures::Subscription; use crate::futures::Subscription;
use crate::futures::futures::channel::oneshot;
use crate::program::Program; use crate::program::Program;
use crate::runtime::Task; use crate::runtime::Task;
use crate::widget::{bottom_right, container, stack, text, themer}; use crate::widget::{bottom_right, container, stack, text, themer};
use std::fmt; use std::fmt;
use std::thread;
pub fn attach(program: impl Program + 'static) -> impl Program { pub fn attach(program: impl Program + 'static) -> impl Program {
struct Attach<P> { struct Attach<P> {
@ -113,9 +115,19 @@ where
state, state,
show_notification: true, show_notification: true,
}, },
Task::perform(smol::Timer::after(seconds(2)), |_| { Task::perform(
Message::HideNotification async move {
}), let (sender, receiver) = oneshot::channel();
let _ = thread::spawn(|| {
thread::sleep(seconds(2));
let _ = sender.send(());
});
let _ = receiver.await;
},
|_| Message::HideNotification,
),
) )
} }