Skip to content
Extraits de code Groupes Projets
Valider 098008e7 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

SEARCH: fix tokio::spawn spawning block_on calling function

parent 14168697
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -21,6 +21,7 @@ use lektor_utils::decode_base64_json; ...@@ -21,6 +21,7 @@ use lektor_utils::decode_base64_json;
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use std::ops::RangeBounds; use std::ops::RangeBounds;
use tokio::task::LocalSet; use tokio::task::LocalSet;
use tokio::task::spawn_blocking;
/// Get informations abount the lektord server. /// Get informations abount the lektord server.
#[axum::debug_handler(state = LektorStatePtr)] #[axum::debug_handler(state = LektorStatePtr)]
...@@ -557,7 +558,7 @@ macro_rules! extractor { ...@@ -557,7 +558,7 @@ macro_rules! extractor {
=> { $($match_pat:pat => $match_handle:expr,)+ } => { $($match_pat:pat => $match_handle:expr,)+ }
=> |$arg:ident| $handle:expr $(,)? => |$arg:ident| $handle:expr $(,)?
) => { ) => {
async move { move || {
tokio::runtime::Builder::new_current_thread() tokio::runtime::Builder::new_current_thread()
.build() .build()
.context("failed to build the runtime")? .context("failed to build the runtime")?
...@@ -578,7 +579,7 @@ pub(crate) async fn search( ...@@ -578,7 +579,7 @@ pub(crate) async fn search(
Path(uri): Path<String>, Path(uri): Path<String>,
) -> Result<Json<Vec<KId>>, LektordError> { ) -> Result<Json<Vec<KId>>, LektordError> {
let SearchData { from, regex } = decode_base64_json(uri)?; let SearchData { from, regex } = decode_base64_json(uri)?;
Ok(tokio::spawn(extractor! { Ok(spawn_blocking(extractor! {
match from match from
=> { => {
SearchFrom::Database => search_adaptors::database_extractor(&state).await, SearchFrom::Database => search_adaptors::database_extractor(&state).await,
...@@ -603,7 +604,7 @@ pub(crate) async fn count( ...@@ -603,7 +604,7 @@ pub(crate) async fn count(
Path(uri): Path<String>, Path(uri): Path<String>,
) -> Result<Json<usize>, LektordError> { ) -> Result<Json<usize>, LektordError> {
let SearchData { from, regex } = decode_base64_json(uri)?; let SearchData { from, regex } = decode_base64_json(uri)?;
Ok(tokio::spawn(extractor! { Ok(spawn_blocking(extractor! {
match from match from
=> { => {
SearchFrom::Database => search_adaptors::database_extractor(&state).await, SearchFrom::Database => search_adaptors::database_extractor(&state).await,
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter