elfo icon indicating copy to clipboard operation
elfo copied to clipboard

Non-blocking requests

Open loyd opened this issue 1 year ago • 4 comments

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.

loyd avatar Jun 02 '23 08:06 loyd