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?
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.