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

Signal::into_inner #3068

Closed
stefnotch opened this issue Oct 7, 2024 · 3 comments · Fixed by #3343
Closed

Signal::into_inner #3068

stefnotch opened this issue Oct 7, 2024 · 3 comments · Fixed by #3343

Comments

@stefnotch
Copy link
Contributor

stefnotch commented Oct 7, 2024

Is your feature request related to a problem? Please describe.

I am using Leptos to manage large objects, including WebGPU objects that cannot be cloned. I would wrap the object in a signal, do some reactive operations with it, and would subsequently like to get the object back.

A very similar case came up while I was trying to implement a pop method for struct SignalVec<T> { ArcRwSignal<Vec<ArcRwSignal<T>>> } . See #3066

Describe the solution you'd like
I'd love it if there were a function analogous to the standard library RwLock/Arc::into_inner.

// for the ArcRwSignal

/// Returns the inner value if this is the only reference to to the signal.
/// Otherwise, returns `None`.
/// # Panics
/// Panics if the inner lock is poisoned.
#[track_caller]
pub fn into_inner(self) -> Option<T> {
    // I believe the subscribers don't matter here, because they aren't holding a reference to the value.
    Arc::into_inner(self.value)?.into_inner().ok()
}

Describe alternatives you've considered
Using clunky workarounds, such as wrapping my objects into Options, and taking the values out of the options.

@stefnotch
Copy link
Contributor Author

I would be willing to contribute a pull request with such a feature and unit tests.

@gbj
Copy link
Collaborator

gbj commented Oct 7, 2024

PR very welcome! Sounds like a great addition.

(The same can be done for arena-stored types as well, if they are first disposed.)

@stefnotch
Copy link
Contributor Author

I have started working on this, pull request hopefully coming soon. :)

(Still missing unit tests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants