async_helpers::hanging_get::async_server

Struct HangingGet

Source
pub struct HangingGet<S, K, O, F: Fn(&S, O) -> bool> { /* private fields */ }
Expand description

Deprecated: New code should use [async_utils::hanging_get::server::HangingGet].

TODO(https://fxbug.dev/42055741): Remove this struct.

A HangingGet object manages some internal state S and notifies observers of type O when their view of the state is outdated.

S - the type of State to be watched O - the type of Observers of S F - the type of observer notification behavior, where F: Fn(&S, O) K - the Key by which Observers are identified

While it can be used directly, most API consumers will want to use the higher level HangingGetBroker object. HangingGetBroker and its companion types provide Send for use from multiple threads or async tasks.

Implementations§

Source§

impl<S, K, O, F> HangingGet<S, K, O, F>
where K: Eq + Hash, F: Fn(&S, O) -> bool,

Source

pub fn new(state: S, notify: F) -> Self

Create a new HangingGet. state is the initial state of the HangingGet notify is a Fn that is used to notify observers of state.

Source

pub fn set(&mut self, state: S)

Set the internal state value to state and notify all observers. Note that notification is not conditional on the value set by calling the set function. Notification will occur regardless of whether the state value differs from the value currently stored by HangingGet.

Source

pub fn update(&mut self, state_update: impl FnOnce(&mut S) -> bool)

Modify the internal state in-place using the state_update function. Notify all observers if state_update returns true.

Source

pub fn subscribe( &mut self, key: K, observer: O, ) -> Result<(), HangingGetServerError>

Register an observer as a subscriber of the state. Observers are grouped by key and all observers will the same key are assumed to have received the latest state update. If an observer with a previously unseen key subscribes, it is immediately notified to the stated. If an observer with a known key subscribes, it will only be notified when the state is updated since last sent to an observer with the same key. All unresolved observers will be resolved to the same value immediately after the state is updated.

Source

pub fn unsubscribe(&mut self, key: K)

Deregister all observers that subscribed with key. If an observer is subsequently subscribed with the same key value, it will be treated as a previously unseen key.

Auto Trait Implementations§

§

impl<S, K, O, F> Freeze for HangingGet<S, K, O, F>
where S: Freeze, F: Freeze,

§

impl<S, K, O, F> RefUnwindSafe for HangingGet<S, K, O, F>

§

impl<S, K, O, F> Send for HangingGet<S, K, O, F>
where S: Send, F: Send, K: Send, O: Send,

§

impl<S, K, O, F> Sync for HangingGet<S, K, O, F>
where S: Sync, F: Sync, K: Sync, O: Sync,

§

impl<S, K, O, F> Unpin for HangingGet<S, K, O, F>
where S: Unpin, F: Unpin, K: Unpin, O: Unpin,

§

impl<S, K, O, F> UnwindSafe for HangingGet<S, K, O, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<St> WithTag for St

§

fn tagged<T>(self, tag: T) -> Tagged<T, St>

Produce a new stream from this one which yields item tupled with a constant tag