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 upgrade_or_insert{_with} to WeakRefs #1249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ZanderBrown
Copy link
Contributor

Avoids some boilerplate when implementing things like single-window apps, where you don't really care if the object was already set, you just need an object

Avoids some boilerplate when implementing things like single-window
apps, where you don't really care if the object was already set, you
just need an object
/// If the stored object was already destroyed or no object was set, the
/// reference is updated to the result of `f`, which is then returned
#[inline]
pub fn upgrade_or_insert_with<F>(&self, f: F) -> T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unfortunately racy if called from multiple threads at once. That at least should be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes. I suppose we can't do much about that without new upstream API? bother.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so

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

Successfully merging this pull request may close these issues.

None yet

2 participants