elfo
elfo copied to clipboard
Non-blocking requests
API for non-blocking requests.
Something like this:
#[message(ret = u32)]
struct SomeRequest(u32);
let request_map = RequestMap::new(); // `SecondaryMap` underhood
let request_id = ctx.request(SomeRequest(42)).id().await;
// Store additional information
request_map.insert(request_id, SomeInfo { name: "kek" });
while let Some(envelope) = ctx.recv().await {
msg!(match envelope {
SomeRequest::Response(request_id, ret) => {
let info = request_map.take(request_id);
info!(message = "got it", name = %info.name, ret = %ret);
}
SomeRequest::Error(err) => { .. }
});
}
For the receiving part, nothing is changed.