Struct aldrin::LifetimeScope
source · pub struct LifetimeScope { /* private fields */ }
Expand description
A scope that notifies other clients when ends.
Aldrin services are inherently stateless with respect to the clients that are using them. Sometimes it becomes necessary to know when a client is no longer interested in using a service.
Scopes and Lifetime
s solve this problem in a robust way. One client can create a
LifetimeScope
while another binds a Lifetime
to it. The Lifetime
will then notify when the
scope ends. This can be triggered explicitly (end
) or implicitly by dropping the
scope. A scope also ends when the client that owns it disconnects from be bus for some reason.
§Examples
// Assume client 1 is using a service from client 2. In turn, client 2 needs to know when
// client 1 is done.
// Client 1 creates a scope and passes its id to client 2.
let scope = client1.create_lifetime_scope().await?;
let id = scope.id();
// Client 2 creates a lifetime from the id.
let lifetime = client2.create_lifetime(id).await?;
tokio::spawn(async move {
// Move in the scope and do some work. The scope is dropped at the end.
let _scope = scope;
});
// Resolves when the associated scope ends.
lifetime.await;
Implementations§
source§impl LifetimeScope
impl LifetimeScope
Trait Implementations§
source§impl Debug for LifetimeScope
impl Debug for LifetimeScope
source§impl Serialize for LifetimeScope
impl Serialize for LifetimeScope
fn serialize(&self, serializer: Serializer<'_>) -> Result<(), SerializeError>
Auto Trait Implementations§
impl Freeze for LifetimeScope
impl !RefUnwindSafe for LifetimeScope
impl Send for LifetimeScope
impl Sync for LifetimeScope
impl Unpin for LifetimeScope
impl !UnwindSafe for LifetimeScope
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