Async_std and futures

To understand futures and async_std I would like to do this:

Send a message from A to B and get a response back. For instance I would like to have a method that looks like the following:

pub fn send_rr(msg : Vec, to : Host) -> Future
// do some work
return future;

Caller should do (typical in Java for instance):

let fut = send_rr(msg, to);
// not block so basically .await here.
let val = fut.get();

Are such futures readily baked in or should write one on my own? If so any examples that anyone can point me to using async_std?

Sounds like you are looking for message passing channels.

In async_std, you can find these in the channel module.

Since async_std::channel has very little documentation, you might also want to look at the std::sync::mpsc module. These channels from the standard library have a very similar API, except they are for communicating synchronously between threads, rather than asynchronously between tasks. (Don't use the standard library channels in async code; I'm only linking to them because reading the documentation may be useful.)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.