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
28
29
30
31
32
use std::sync::Arc;
use futures_util::{stream::BoxStream, StreamExt};
use crate::{BatchRequest, BatchResponse, Data, Request, Response};
#[async_trait::async_trait]
pub trait Executor: Unpin + Clone + Send + Sync + 'static {
async fn execute(&self, request: Request) -> Response;
async fn execute_batch(&self, batch_request: BatchRequest) -> BatchResponse {
match batch_request {
BatchRequest::Single(request) => BatchResponse::Single(self.execute(request).await),
BatchRequest::Batch(requests) => BatchResponse::Batch(
futures_util::stream::iter(requests.into_iter())
.then(|request| self.execute(request))
.collect()
.await,
),
}
}
fn execute_stream(
&self,
request: Request,
session_data: Option<Arc<Data>>,
) -> BoxStream<'static, Response>;
}