Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glib: Add #[weak_no_upgrade] that requires manual upgrades in the body #1460

Open
sdroege opened this issue Jul 17, 2024 · 0 comments
Open
Milestone

Comments

@sdroege
Copy link
Member

sdroege commented Jul 17, 2024

Use case is something like this

    glib::spawn_future_local(clone!(
        #[weak]
        button,
        async move {
            while let Ok(enable_button) = receiver.recv().await {
                button.set_sensitive(enable_button);
            }
        }
    ));

The intention here clearly is that this is stopped to be called when the button goes away, but that is not the case. The future will always have a strong reference to the button once it was called for the first time and the button can never go away.

Something like this would be needed

    glib::spawn_future_local(clone!(
        #[weak_no_upgrade]
        button,
        async move {
            while let Ok(enable_button) = receiver.recv().await {
                let Some(button) = button.upgrade() else {
                    break;
                };
                button.set_sensitive(enable_button);
            }
        }
    ));
@sdroege sdroege added this to the 0.21 milestone Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant