From 00ee6ab47a0eefbce3db533eb94c5f954d9e8a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 5 Apr 2025 20:14:51 +0200 Subject: [PATCH] Spawn a thread to sleep asynchronously in `devtools` ... instead of relying on an external reactor. --- Cargo.lock | 1 - devtools/Cargo.toml | 3 --- devtools/src/lib.rs | 18 +++++++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1cd57e6..0142993c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2462,7 +2462,6 @@ dependencies = [ "iced_debug", "iced_program", "iced_widget", - "smol", ] [[package]] diff --git a/devtools/Cargo.toml b/devtools/Cargo.toml index 927398bf..df7e5012 100644 --- a/devtools/Cargo.toml +++ b/devtools/Cargo.toml @@ -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 diff --git a/devtools/src/lib.rs b/devtools/src/lib.rs index cec392ff..19540c87 100644 --- a/devtools/src/lib.rs +++ b/devtools/src/lib.rs @@ -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

{ @@ -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, + ), ) }