Crate async_object
source · [−]Expand description
Async Object
This crate provides reference-counting wrappers and support for event publishing/subscription for using objects in multithread asynchronous environment.
The main purpose of the library is to provide foundation for my experimental GUI library WAG, but it’s abstract enough to be used anywhere else.
Library implements CArcArc<RwLock<T>
inside.
CArc
provides methods for accessing T
both in synchronous and asychronous environment.
Sync methods CArc::call blocks calling thread, async ones CArc::async_call releases task if wrapper object
is locked, allowing other async tasks to continue.
Example:
use async_object::CArc;
let obj = CArc::new(42 as usize);
obj.call_mut(|v| *v += 1 );
Library also provides event queue EArc which allows to subscribe to async stream of events.
Structs
Reference-counting pointer based on Arc<RwLock<T>>
with methods for access wrapped data from asynchronous code
Reference-counting object based on Arc<RwLock<...>>
with methods for broadcasting events
Container for event. The main purpose of this container is to ensure correct order of events. Asyncronous send_event function finishes only when all copies of Event are destroyed. This allows to guarantee that sent event have been processed by all handlers by the moment when send_event returns.
Clonable container containing instance of specific Event which hides type of concrete event.
Asychronous stream of events of specified type generated by EArc object. The stream’s next()
method returns Some(Event<EVT>)
while
source object EArc
is alive and None
when EArc
is destroyed.