build: allow to switch async runtime
This commit is contained in:
@@ -62,16 +62,25 @@ pub trait MaiVersionExt: MaiVersion {
|
||||
fn request_raw<D>(
|
||||
client: &AsyncClient,
|
||||
api: APIMethod,
|
||||
agent_extra: impl Display,
|
||||
agent_extra: impl Display + Send + 'static,
|
||||
data: D,
|
||||
) -> impl Future<Output = Result<Vec<u8>, ApiError>>
|
||||
where
|
||||
D: Serialize,
|
||||
D: Serialize + Send + 'static,
|
||||
{
|
||||
#[cfg(feature = "compio")]
|
||||
use compio::runtime::spawn_blocking;
|
||||
#[cfg(feature = "tokio")]
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
async {
|
||||
let req = Self::api_call(api, agent_extra, data)?;
|
||||
let req = spawn_blocking(move || Self::api_call(api, agent_extra, data))
|
||||
.await
|
||||
.map_err(|_| ApiError::JoinError)??;
|
||||
let data = client.request(req).await?.bytes().await?;
|
||||
let decoded = Self::decode(data)?;
|
||||
let decoded = spawn_blocking(move || Self::decode(data))
|
||||
.await
|
||||
.map_err(|_| ApiError::JoinError)??;
|
||||
Ok(decoded)
|
||||
}
|
||||
}
|
||||
@@ -79,11 +88,11 @@ pub trait MaiVersionExt: MaiVersion {
|
||||
fn request<D, R>(
|
||||
client: &AsyncClient,
|
||||
api: APIMethod,
|
||||
agent_extra: impl Display,
|
||||
agent_extra: impl Display + Send + 'static,
|
||||
data: D,
|
||||
) -> impl Future<Output = Result<R, ApiError>>
|
||||
where
|
||||
D: Serialize,
|
||||
D: Serialize + Send + 'static,
|
||||
R: for<'a> Deserialize<'a>,
|
||||
{
|
||||
async {
|
||||
|
||||
Reference in New Issue
Block a user