1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::retry::Policy as RetryPolicy;
use std::future::Future;

pub trait ExecuteQuery<Request> {
    type Response;

    fn query(&self, request: Request) -> impl Future<Output = Self::Response> + Send;

    fn query_with_retry(&self, request: Request) -> impl Future<Output = Self::Response> + Send
    where
        Request: Clone,
        Self::Response: Send;

    fn query_with_policy<Policy>(
        &self,
        request: Request,
        policy: Policy,
    ) -> impl Future<Output = Self::Response> + Send
    where
        Request: Clone + Send,
        Policy: RetryPolicy<Self::Response> + Send,
        Self::Response: Send,
        Self: Sync,
    {
        async move { policy.retry(|req| self.query(req), (request,)).await }
    }
}