* [pdm-devel] [PATCH datacenter-manager v2] ui: resource tree: use AsyncAbortGuard to cancel obsolete pending loads
@ 2025-04-18 7:46 Dominik Csapak
2025-04-22 20:13 ` Thomas Lamprecht
0 siblings, 1 reply; 3+ messages in thread
From: Dominik Csapak @ 2025-04-18 7:46 UTC (permalink / raw)
To: pdm-devel
Currently, if a new serach term is given, a new load will occur if the
INPUT_BUFFER_MS time is reached. Any old in-flight API requests are not
canceled, and might still arrive.
To prevent that, use an AsyncAbortGuard so the old load will be aborted
whenever it is overwritten.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* use AsyncAbortGuard instead of AsyncPool, since that's the correct
abstraction here.
* introduce a new Msg variant, so that we can overwrite the AsyncAbortGuard
in the update method
replaces:
https://lore.proxmox.com/pdm-devel/20250416113232.2488103-1-d.csapak@proxmox.com/
ui/src/widget/resource_tree.rs | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/ui/src/widget/resource_tree.rs b/ui/src/widget/resource_tree.rs
index feff308..ddfd7cb 100644
--- a/ui/src/widget/resource_tree.rs
+++ b/ui/src/widget/resource_tree.rs
@@ -18,6 +18,7 @@ use pwt::{
},
ActionIcon, Column, Container, Fa, Panel, Progress, Row, Tooltip,
},
+ AsyncAbortGuard,
};
use pwt_macros::{builder, widget};
@@ -88,6 +89,7 @@ async fn load_resources(search_term: String) -> Result<Vec<RemoteResources>, Err
}
pub enum Msg {
+ LoadRequest,
Load,
LoadResult(Result<Vec<RemoteResources>, Error>),
RemoteListChanged(RemoteList),
@@ -101,6 +103,7 @@ pub struct PdmResourceTree {
_context_listener: ContextHandle<RemoteList>,
selection: Selection,
_load_timeout: Option<Timeout>,
+ _load_guard: Option<AsyncAbortGuard>,
}
impl PdmResourceTree {}
@@ -117,7 +120,7 @@ impl Component for PdmResourceTree {
.expect("No Remote list context provided");
if !props.search_only || !props.search_term.is_empty() {
- ctx.link().clone().send_message(Msg::Load);
+ ctx.link().clone().send_message(Msg::LoadRequest);
}
let store = TreeStore::new().view_root(false);
@@ -131,25 +134,32 @@ impl Component for PdmResourceTree {
_context_listener,
selection,
_load_timeout: None,
+ _load_guard: None,
}
}
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
- Msg::Load => {
+ Msg::LoadRequest => {
let props = ctx.props();
let link = ctx.link().clone();
- let search_term = props.search_term.clone();
- if props.search_only && !search_term.is_empty() {
+ if props.search_only && !props.search_term.is_empty() {
self._load_timeout = Some(Timeout::new(INPUT_BUFFER_MS, move || {
- link.send_future(async move {
- Msg::LoadResult(load_resources(search_term).await)
- });
+ link.send_message(Msg::Load);
}));
self.loading = true;
}
true
}
+ Msg::Load => {
+ let props = ctx.props();
+ let link = ctx.link().clone();
+ let search_term = props.search_term.clone();
+ self._load_guard = Some(AsyncAbortGuard::spawn(async move {
+ link.send_message(Msg::LoadResult(load_resources(search_term).await))
+ }));
+ false
+ }
Msg::LoadResult(res) => {
match res {
Ok(result) => {
@@ -189,7 +199,7 @@ impl Component for PdmResourceTree {
let reload = self.remote_list.len() != list.len();
self.remote_list = list;
if reload && !self.remote_list.is_empty() {
- ctx.link().send_message(Msg::Load);
+ ctx.link().send_message(Msg::LoadRequest);
}
true
}
@@ -200,7 +210,7 @@ impl Component for PdmResourceTree {
let props = ctx.props();
if props.search_term != old_props.search_term {
if !props.search_only || !props.search_term.is_empty() {
- ctx.link().clone().send_message(Msg::Load);
+ ctx.link().clone().send_message(Msg::LoadRequest);
} else if props.search_term.is_empty() {
// clear grid
ctx.link()
--
2.39.5
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pdm-devel] [PATCH datacenter-manager v2] ui: resource tree: use AsyncAbortGuard to cancel obsolete pending loads
2025-04-18 7:46 [pdm-devel] [PATCH datacenter-manager v2] ui: resource tree: use AsyncAbortGuard to cancel obsolete pending loads Dominik Csapak
@ 2025-04-22 20:13 ` Thomas Lamprecht
2025-04-23 6:49 ` Dominik Csapak
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Lamprecht @ 2025-04-22 20:13 UTC (permalink / raw)
To: Proxmox Datacenter Manager development discussion, Dominik Csapak
Am 18.04.25 um 09:46 schrieb Dominik Csapak:
> Currently, if a new serach term is given, a new load will occur if the
> INPUT_BUFFER_MS time is reached. Any old in-flight API requests are not
> canceled, and might still arrive.
>
> To prevent that, use an AsyncAbortGuard so the old load will be aborted
> whenever it is overwritten.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from v1:
> * use AsyncAbortGuard instead of AsyncPool, since that's the correct
> abstraction here.
> * introduce a new Msg variant, so that we can overwrite the AsyncAbortGuard
> in the update method
>
> replaces:
> https://lore.proxmox.com/pdm-devel/20250416113232.2488103-1-d.csapak@proxmox.com/
Yeah, this reads a bit nicer and more convenient.
> ui/src/widget/resource_tree.rs | 28 +++++++++++++++++++---------
> 1 file changed, 19 insertions(+), 9 deletions(-)
>
> @@ -88,6 +89,7 @@ async fn load_resources(search_term: String) -> Result<Vec<RemoteResources>, Err
> }
>
> pub enum Msg {
> + LoadRequest,
Tiny nit: would it be a tiny bit more and telling and consistent with pwt if we
would name this message "UpdateFilter"? E.g. like PwtSearchDropdown uses.
Could be adapted on applying though.
> Load,
> LoadResult(Result<Vec<RemoteResources>, Error>),
> RemoteListChanged(RemoteList),
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pdm-devel] [PATCH datacenter-manager v2] ui: resource tree: use AsyncAbortGuard to cancel obsolete pending loads
2025-04-22 20:13 ` Thomas Lamprecht
@ 2025-04-23 6:49 ` Dominik Csapak
0 siblings, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-04-23 6:49 UTC (permalink / raw)
To: Thomas Lamprecht, Proxmox Datacenter Manager development discussion
On 4/22/25 22:13, Thomas Lamprecht wrote:
> Am 18.04.25 um 09:46 schrieb Dominik Csapak:
>> Currently, if a new serach term is given, a new load will occur if the
>> INPUT_BUFFER_MS time is reached. Any old in-flight API requests are not
>> canceled, and might still arrive.
>>
>> To prevent that, use an AsyncAbortGuard so the old load will be aborted
>> whenever it is overwritten.
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>> changes from v1:
>> * use AsyncAbortGuard instead of AsyncPool, since that's the correct
>> abstraction here.
>> * introduce a new Msg variant, so that we can overwrite the AsyncAbortGuard
>> in the update method
>>
>> replaces:
>> https://lore.proxmox.com/pdm-devel/20250416113232.2488103-1-d.csapak@proxmox.com/
>
> Yeah, this reads a bit nicer and more convenient.
>
>> ui/src/widget/resource_tree.rs | 28 +++++++++++++++++++---------
>> 1 file changed, 19 insertions(+), 9 deletions(-)
>>
>
>> @@ -88,6 +89,7 @@ async fn load_resources(search_term: String) -> Result<Vec<RemoteResources>, Err
>> }
>>
>> pub enum Msg {
>> + LoadRequest,
>
> Tiny nit: would it be a tiny bit more and telling and consistent with pwt if we
> would name this message "UpdateFilter"? E.g. like PwtSearchDropdown uses.
>
> Could be adapted on applying though.
yes that makes sense. Would be great if you could adapt that on applying
if there is nothing else to change
>
>> Load,
>> LoadResult(Result<Vec<RemoteResources>, Error>),
>> RemoteListChanged(RemoteList),
>
>
>
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-23 6:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-18 7:46 [pdm-devel] [PATCH datacenter-manager v2] ui: resource tree: use AsyncAbortGuard to cancel obsolete pending loads Dominik Csapak
2025-04-22 20:13 ` Thomas Lamprecht
2025-04-23 6:49 ` Dominik Csapak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal