pub struct SubscriptionRef<K, V>{ /* private fields */ }
Expand description
A transparent wrapper for the underlying subscription in the map which manages the subscription count and removes the observable if no one holds a subscription to it.
Methods from Deref<Target = Observable<V>>§
Sourcepub fn modify_conditional<C, M>(&mut self, condition: C, modify: M) -> bool
pub fn modify_conditional<C, M>(&mut self, condition: C, modify: M) -> bool
If the condition is met, modify the underlying value and notify forks.
Returns true
if the modification was executed.
let mut observable = Observable::new(0);
let mut fork = observable.clone();
observable.modify_conditional(|i| *i == 0, |i| *i = 1); // modify
assert_eq!(fork.next().await, 1);
observable.modify_conditional(|i| *i == 0, |i| *i = 2); // doesnt modify
fork.next().await; // runs forever
Sourcepub fn clone_and_reset(&self) -> Observable<T>
pub fn clone_and_reset(&self) -> Observable<T>
Same as clone, but the reset causes the fork to instantly have a change available with the current state.
let mut observable = Observable::new(0);
let mut fork = observable.clone_and_reset();
assert_eq!(fork.next().await, 0);
Sourcepub fn latest(&self) -> T
pub fn latest(&self) -> T
Creates a clone of latest version of the observable value, without consuming the change!
let mut observable = Observable::new(0);
let mut fork = observable.clone_and_reset();
observable.publish(1);
assert_eq!(fork.latest(), 1);
assert_eq!(fork.next().await, 1);
Sourcepub async fn next(&mut self) -> T
pub async fn next(&mut self) -> T
Wait until a new version of the observable was published and return a clone of the new version.
let (mut a, mut b) = Observable::new(0).split();
a.publish(1);
assert_eq!(b.next().await, 1);
a.publish(2);
assert_eq!(b.next().await, 2);
b.next().await; // runs forever!
Sourcepub fn synchronize(&mut self) -> T
pub fn synchronize(&mut self) -> T
Skip any potential updates and retrieve the latest version of the observed value.
let (mut a, mut b) = Observable::new(0).split();
a.publish(1);
a.publish(2);
a.publish(3);
assert_eq!(b.synchronize(), 3);
b.next().await; // runs forever!
Sourcepub fn publish_if_changed(&mut self, value: T) -> bool
pub fn publish_if_changed(&mut self, value: T) -> bool
Publish a change if the new value differs from the current one.
Returns true
if a change was made.
Trait Implementations§
Source§impl<K, V> Debug for SubscriptionRef<K, V>
impl<K, V> Debug for SubscriptionRef<K, V>
Source§impl<K, V> Deref for SubscriptionRef<K, V>
impl<K, V> Deref for SubscriptionRef<K, V>
Source§impl<K, V> DerefMut for SubscriptionRef<K, V>
impl<K, V> DerefMut for SubscriptionRef<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for SubscriptionRef<K, V>where
K: Freeze,
impl<K, V> !RefUnwindSafe for SubscriptionRef<K, V>
impl<K, V> Send for SubscriptionRef<K, V>
impl<K, V> Sync for SubscriptionRef<K, V>
impl<K, V> Unpin for SubscriptionRef<K, V>where
K: Unpin,
impl<K, V> !UnwindSafe for SubscriptionRef<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more