@@ -2,14 +2,16 @@ use std::time::Duration;
2
2
3
3
#[ derive( Debug , Copy , Clone ) ]
4
4
pub ( crate ) enum SleepBackend {
5
+ #[ cfg( all( not( target_arch = "wasm32" ) , feature = "reqwest" ) ) ]
6
+ Tokio ,
5
7
#[ cfg( not( target_arch = "wasm32" ) ) ]
6
8
Thread ,
7
9
#[ cfg( target_arch = "wasm32" ) ]
8
10
Javascript ,
9
11
}
10
12
11
13
impl SleepBackend {
12
- pub ( crate ) fn infer ( ) -> Self {
14
+ pub ( crate ) fn infer ( is_tokio : bool ) -> Self {
13
15
#[ cfg( not( target_arch = "wasm32" ) ) ]
14
16
return Self :: Thread ;
15
17
@@ -19,6 +21,10 @@ impl SleepBackend {
19
21
20
22
pub ( crate ) async fn sleep ( self , interval : Duration ) {
21
23
match self {
24
+ #[ cfg( all( not( target_arch = "wasm32" ) , feature = "reqwest" ) ) ]
25
+ Self :: Tokio => {
26
+ tokio:: time:: sleep ( interval) . await ;
27
+ }
22
28
#[ cfg( not( target_arch = "wasm32" ) ) ]
23
29
Self :: Thread => {
24
30
let ( sender, receiver) = futures_channel:: oneshot:: channel :: < ( ) > ( ) ;
@@ -54,6 +60,17 @@ mod test {
54
60
use super :: * ;
55
61
use meilisearch_test_macro:: meilisearch_test;
56
62
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
+
57
74
#[ cfg( not( target_arch = "wasm32" ) ) ]
58
75
#[ meilisearch_test]
59
76
async fn sleep_thread ( ) {
0 commit comments