Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: distributor request fn #321

Merged
merged 9 commits into from
Apr 13, 2021
Merged

Conversation

o0Ignition0o
Copy link
Contributor

@o0Ignition0o o0Ignition0o commented Apr 9, 2021

Proposal: Distributor request fn.

as shown here making a whole request can sometimes be a bit convoluted. the Distributor::request() function aims to be syntactic sugar to wrap this.

let answer = probes
    .ask_one(url.clone())
    .expect("couldn't send message to probes");

// Handle a reply
MessageHandler::new(answer.await.expect("couldn't get an answer")).on_tell(
    |probe_result: ProbeRunStatus, _| {
        info!("probe is done: {:?}", probe_result);
    },
);

will then become

let probe_run_status: Result<ProbeRunStatus, SendError> = probes
        .request(url.clone())
        .await
        .expect("couldn't receive reply");
 info!("probe is done: {:?}", probe_result);

It uses a channel() behind the scene, as shown in the signature:

pub fn request<R: Message>(
    &self,
    question: impl Message
) -> Receiver<Result<R, SendError>>

Here's what the documentation looks like so far:

image

there's also a request_sync variant which is backed by a mpsc::channel(), and can be called like this:

let reply: Result<ProbeRunStatus, SendError> = distributor
   .request_sync(url.clone())
   .recv()
   .expect("couldn't receive reply");
 info!("probe is done: {:?}", probe_result);
Checklist
  • tests are passing with cargo test.
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message is clear

@o0Ignition0o o0Ignition0o merged commit 90b8a09 into master Apr 13, 2021
@o0Ignition0o o0Ignition0o deleted the igni/distributor_request branch April 13, 2021 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants