Expand description
§aligne
A crate to help synchronizing asynchronous request / responses.
§Example:
#[tokio::main]
pub async fn main() {
let handle = aligne::ResponseManager::spawn();
let remote_a = handle.remote();
let remote_b = remote_a.clone();
let _h1 = tokio::spawn(async move {
let msg = remote_b.request(2).await;
assert_eq!(msg, "message 2");
let msg = remote_b.request(1).await;
assert_eq!(msg, "message 1");
});
let _h2 = tokio::spawn(async move {
remote_a.receive(1, "message 1").await;
remote_a.receive(2, "message 2").await;
});
_h1.await.unwrap();
_h2.await.unwrap();
}
Structs§
- Response
Manager - Encapsulates an asynchronous task that receives responses and requests asynchronously and matches them by id (
u64
). once both the response and the request are received, the request complete its future and receive the response. - Response
Manager Handle - Handle to the task of a
crate::ResponseManager
, can spawnself::ResponseManagerRemote
to interact with the task. - Response
Manager Remote - Remote to a
crate::ResponseManager
task. can send responses and await requests that will be matched by ids (u64
)