-1

Hi I have a system which pulls some data from different sources. All sources until today were sync so i designed the following API:


trait GraphPuller {
  pub fn Graph() -> Result<Vec<i64>>
}

struct GitPuller;
Struct TcpPuller;

impl GraphPuller for GitPuller {
  pub fn Graph() -> Result<Vec<i64>> {
  ...
  }
}

impl GraphPuller for Tc[Puller {
  pub fn Graph() -> Result<Vec<i64>> {
  ...
  }
}

Now I have to implement the Puller for AWS. AWS API is async, so i have to call async function in non sync system.

How Should I design the trait and api to avoid issues?

Daniel Hornik
  • 1,957
  • 1
  • 14
  • 33
  • 2
    Does this answer your question: [How do I synchronously return a value calculated in an asynchronous Future in stable Rust?](https://stackoverflow.com/questions/52521201/how-do-i-synchronously-return-a-value-calculated-in-an-asynchronous-future-in-st) or the other way: [How can I define an async method in a trait?](https://stackoverflow.com/questions/65921581/how-can-i-define-an-async-method-in-a-trait) – kmdreko Nov 08 '21 at 22:43
  • Thank you it was very helpful to understand problem, however I had to block until future is returned and then return result, as interface i am describing is bigger than i show here. :) – Daniel Hornik Nov 12 '21 at 18:04

1 Answers1

0

The easiest way is to keep the trait the same and to just block on the Amazon API calls. I'd recommend pollster::block_on because it implements just the very minimum instead of pulling in the more heavyweight futures crate.

VۛJ
  • 49
  • 1
  • 3
  • Thank you It helped me. I did not refactore entire module, however We will think how to refactor it. I am not super familiar with Rust. I am still learning it, and I do not know all of its limitaitons. – Daniel Hornik Nov 12 '21 at 18:03