@@ -2,14 +2,16 @@ use std::time::Duration;
22
33#[ derive( Debug , Copy , Clone ) ]
44pub ( crate ) enum SleepBackend {
5+ #[ cfg( all( not( target_arch = "wasm32" ) , feature = "reqwest" ) ) ]
6+ Tokio ,
57 #[ cfg( not( target_arch = "wasm32" ) ) ]
68 Thread ,
79 #[ cfg( target_arch = "wasm32" ) ]
810 Javascript ,
911}
1012
1113impl SleepBackend {
12- pub ( crate ) fn infer ( ) -> Self {
14+ pub ( crate ) fn infer ( is_tokio : bool ) -> Self {
1315 #[ cfg( not( target_arch = "wasm32" ) ) ]
1416 return Self :: Thread ;
1517
@@ -19,6 +21,10 @@ impl SleepBackend {
1921
2022 pub ( crate ) async fn sleep ( self , interval : Duration ) {
2123 match self {
24+ #[ cfg( all( not( target_arch = "wasm32" ) , feature = "reqwest" ) ) ]
25+ Self :: Tokio => {
26+ tokio:: time:: sleep ( interval) . await ;
27+ }
2228 #[ cfg( not( target_arch = "wasm32" ) ) ]
2329 Self :: Thread => {
2430 let ( sender, receiver) = futures_channel:: oneshot:: channel :: < ( ) > ( ) ;
@@ -54,6 +60,17 @@ mod test {
5460 use super :: * ;
5561 use meilisearch_test_macro:: meilisearch_test;
5662
63+ #[ cfg( all( not( target_arch = "wasm32" ) , feature = "reqwest" ) ) ]
64+ #[ meilisearch_test]
65+ async fn sleep_tokio ( ) {
66+ let sleep_duration = Duration :: from_millis ( 10 ) ;
67+ let now = std:: time:: Instant :: now ( ) ;
68+
69+ SleepBackend :: Tokio . sleep ( sleep_duration) . await ;
70+
71+ assert ! ( now. elapsed( ) >= sleep_duration) ;
72+ }
73+
5774 #[ cfg( not( target_arch = "wasm32" ) ) ]
5875 #[ meilisearch_test]
5976 async fn sleep_thread ( ) {
0 commit comments