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 CArc wrapper containingArc<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§

CArc
Reference-counting pointer based on Arc<RwLock<T>> with methods for access wrapped data from asynchronous code
EArc
Reference-counting object based on Arc<RwLock<...>> with methods for broadcasting events
Event
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.
EventBox
Clonable container containing instance of specific Event which hides type of concrete event.
EventStream
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.
WCArc
Non-owning reference to CArc
WEArc
Non-owning reference to EArc