@@ -20,18 +20,25 @@ use futures_lite::{FutureExt, StreamExt};
20
20
#[ cfg( not( target_family = "wasm" ) ) ]
21
21
use futures_lite:: future;
22
22
23
+ #[ cfg( not( target_family = "wasm" ) ) ]
23
24
fn spawn < T : Send + ' static > (
24
25
f : impl Future < Output = T > + Send + ' static ,
25
26
) -> impl Future < Output = T > + Send + ' static {
26
27
let ( s, r) = async_channel:: bounded ( 1 ) ;
27
28
28
- #[ cfg( not( target_family = "wasm" ) ) ]
29
29
thread:: spawn ( move || {
30
30
future:: block_on ( async {
31
31
s. send ( f. await ) . await . ok ( ) ;
32
32
} )
33
33
} ) ;
34
34
35
+ Box :: pin ( async move { r. recv ( ) . await . unwrap ( ) } )
36
+ }
37
+
38
+ #[ cfg( target_family = "wasm" ) ]
39
+ fn spawn < T : ' static > ( f : impl Future < Output = T > + ' static ) -> impl Future < Output = T > + ' static {
40
+ let ( s, r) = async_channel:: bounded ( 1 ) ;
41
+
35
42
#[ cfg( target_family = "wasm" ) ]
36
43
wasm_bindgen_futures:: spawn_local ( async move {
37
44
s. send ( f. await ) . await . ok ( ) ;
@@ -40,17 +47,6 @@ fn spawn<T: Send + 'static>(
40
47
Box :: pin ( async move { r. recv ( ) . await . unwrap ( ) } )
41
48
}
42
49
43
- #[ cfg( not( target_family = "wasm" ) ) ]
44
- fn block_on < T > ( f : impl Future < Output = T > ) -> T {
45
- future:: block_on ( f)
46
- }
47
-
48
- #[ cfg( target_family = "wasm" ) ]
49
- fn block_on ( f : impl Future < Output = ( ) > + ' static ) {
50
- // TODO: better way of waiting for a future to finish
51
- wasm_bindgen_futures:: spawn_local ( f)
52
- }
53
-
54
50
#[ cfg( not( target_family = "wasm" ) ) ]
55
51
macro_rules! test {
56
52
(
@@ -79,11 +75,10 @@ macro_rules! test {
79
75
async fn $name( ) {
80
76
console_error_panic_hook:: set_once( ) ;
81
77
$bl
82
- }
78
+ }
83
79
} ;
84
80
}
85
81
86
-
87
82
test ! {
88
83
async fn smoke( ) {
89
84
let start = Instant :: now( ) ;
@@ -107,7 +102,7 @@ test! {
107
102
}
108
103
}
109
104
110
- test ! {
105
+ test ! {
111
106
async fn poll_across_tasks( ) {
112
107
let start = Instant :: now( ) ;
113
108
let ( sender, receiver) = async_channel:: bounded( 1 ) ;
@@ -140,7 +135,7 @@ test!{
140
135
#[ cfg( not( target_family = "wasm" ) ) ]
141
136
#[ test]
142
137
fn set ( ) {
143
- block_on ( async {
138
+ future :: block_on ( async {
144
139
let start = Instant :: now ( ) ;
145
140
let timer = Arc :: new ( Mutex :: new ( Timer :: after ( Duration :: from_secs ( 10 ) ) ) ) ;
146
141
0 commit comments