Spawn a thread to sleep asynchronously in devtools
... instead of relying on an external reactor.
This commit is contained in:
parent
132f60c29c
commit
00ee6ab47a
3 changed files with 15 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2462,7 +2462,6 @@ dependencies = [
|
|||
"iced_debug",
|
||||
"iced_program",
|
||||
"iced_widget",
|
||||
"smol",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -17,6 +17,3 @@ workspace = true
|
|||
iced_program.workspace = true
|
||||
iced_widget.workspace = true
|
||||
iced_debug.workspace = true
|
||||
|
||||
# TODO: Use program executor?
|
||||
smol.workspace = true
|
||||
|
|
|
|||
|
|
@ -12,11 +12,13 @@ use crate::core::theme::{self, Base, Theme};
|
|||
use crate::core::time::seconds;
|
||||
use crate::core::window;
|
||||
use crate::futures::Subscription;
|
||||
use crate::futures::futures::channel::oneshot;
|
||||
use crate::program::Program;
|
||||
use crate::runtime::Task;
|
||||
use crate::widget::{bottom_right, container, stack, text, themer};
|
||||
|
||||
use std::fmt;
|
||||
use std::thread;
|
||||
|
||||
pub fn attach(program: impl Program + 'static) -> impl Program {
|
||||
struct Attach<P> {
|
||||
|
|
@ -113,9 +115,19 @@ where
|
|||
state,
|
||||
show_notification: true,
|
||||
},
|
||||
Task::perform(smol::Timer::after(seconds(2)), |_| {
|
||||
Message::HideNotification
|
||||
}),
|
||||
Task::perform(
|
||||
async move {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
|
||||
let _ = thread::spawn(|| {
|
||||
thread::sleep(seconds(2));
|
||||
let _ = sender.send(());
|
||||
});
|
||||
|
||||
let _ = receiver.await;
|
||||
},
|
||||
|_| Message::HideNotification,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue