From 01aa84e41afa556fd4e82ef11f2f55cf443ef1aa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Aug 2024 05:12:42 +0200 Subject: Make `window::close` return and introduce `Task::discard` --- runtime/src/task.rs | 11 +++++++++++ runtime/src/window.rs | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'runtime') diff --git a/runtime/src/task.rs b/runtime/src/task.rs index 4d75ddaa..ec8d7cc7 100644 --- a/runtime/src/task.rs +++ b/runtime/src/task.rs @@ -159,6 +159,17 @@ impl Task { } } + /// Creates a new [`Task`] that discards the result of the current one. + /// + /// Useful if you only care about the side effects of a [`Task`]. + pub fn discard(self) -> Task + where + T: MaybeSend + 'static, + O: MaybeSend + 'static, + { + self.then(|_| Task::none()) + } + /// Creates a new [`Task`] that can be aborted with the returned [`Handle`]. pub fn abortable(self) -> (Self, Handle) where diff --git a/runtime/src/window.rs b/runtime/src/window.rs index cd27cdfe..0d280f1f 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -24,7 +24,7 @@ pub enum Action { Open(Id, Settings, oneshot::Sender), /// Close the window and exits the application. - Close(Id), + Close(Id, oneshot::Sender), /// Gets the [`Id`] of the oldest window. GetOldest(oneshot::Sender>), @@ -230,8 +230,8 @@ pub fn open(settings: Settings) -> (Id, Task) { } /// Closes the window with `id`. -pub fn close(id: Id) -> Task { - task::effect(crate::Action::Window(Action::Close(id))) +pub fn close(id: Id) -> Task { + task::oneshot(|channel| crate::Action::Window(Action::Close(id, channel))) } /// Gets the window [`Id`] of the oldest window. -- cgit