Make window::close return and introduce Task::discard
This commit is contained in:
parent
7740c35a2a
commit
01aa84e41a
5 changed files with 24 additions and 7 deletions
|
|
@ -159,6 +159,17 @@ impl<T> Task<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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<O>(self) -> Task<O>
|
||||
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
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub enum Action {
|
|||
Open(Id, Settings, oneshot::Sender<Id>),
|
||||
|
||||
/// Close the window and exits the application.
|
||||
Close(Id),
|
||||
Close(Id, oneshot::Sender<Id>),
|
||||
|
||||
/// Gets the [`Id`] of the oldest window.
|
||||
GetOldest(oneshot::Sender<Option<Id>>),
|
||||
|
|
@ -230,8 +230,8 @@ pub fn open(settings: Settings) -> (Id, Task<Id>) {
|
|||
}
|
||||
|
||||
/// Closes the window with `id`.
|
||||
pub fn close<T>(id: Id) -> Task<T> {
|
||||
task::effect(crate::Action::Window(Action::Close(id)))
|
||||
pub fn close(id: Id) -> Task<Id> {
|
||||
task::oneshot(|channel| crate::Action::Window(Action::Close(id, channel)))
|
||||
}
|
||||
|
||||
/// Gets the window [`Id`] of the oldest window.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue