pub struct SharedConnectionBlock { /* private fields */ }Expand description
A shared connection block can be used to temporarily block a slot from executing. There can be an arbitrary number of shared connection blocks for any particular slot. If any of the shared connection blocks are blocking the slot, that slot will not be executed when the signal is emitted.
§Examples
use signals2::*;
let sig: Signal<(), i32> = Signal::new();
let conn = sig.connect(|| 4);
assert_eq!(sig.emit(), Some(4));
let blocker1 = conn.shared_block(true); // blocking
let blocker2 = blocker1.clone(); // also blocking, since blocker1 is blocking
assert_eq!(conn.blocker_count(), 2);
assert_eq!(sig.emit(), None); // slot is blocked and will not execute
blocker1.unblock();
assert_eq!(conn.blocker_count(), 1);
assert_eq!(sig.emit(), None); // slot is still blocked
blocker2.unblock();
assert_eq!(conn.blocker_count(), 0);
assert_eq!(sig.emit(), Some(4)); // no more active blockersShared connection blocks automatically unblock themselved when dropped.
use signals2::*;
let sig: Signal<(), i32> = Signal::new();
let conn = sig.connect(|| 4);
assert_eq!(sig.emit(), Some(4));
{
let _blocker = conn.shared_block(true);
assert_eq!(conn.blocker_count(), 1);
assert_eq!(sig.emit(), None);
}
assert_eq!(conn.blocker_count(), 0);
assert_eq!(sig.emit(), Some(4)); // blocker was droppedImplementations§
Sourcepub fn blocking(&self) -> bool
pub fn blocking(&self) -> bool
Returns true if the SharedConnectionBlock is currently blocking, false otherwise.
If this function returns true it is guaranteed that the given slot will not be executed when
the signal is emitted. However, if this function returns false it is not guaranteed that the given
slot will be executed when the signal is emitted because there could be other existing blockers for
the slot.
Trait Implementations§
Auto Trait Implementations§
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