File tree Expand file tree Collapse file tree 3 files changed +40
-11
lines changed Expand file tree Collapse file tree 3 files changed +40
-11
lines changed Original file line number Diff line number Diff line change 1
1
/target
2
2
/Cargo.lock
3
- * .idea /
3
+ * .idea /
4
+ .vscode
Original file line number Diff line number Diff line change @@ -14,18 +14,28 @@ readme = "./README.md"
14
14
[dependencies ]
15
15
anyhow = " 1.0.75"
16
16
bincode = " 1.3.3"
17
+ cfg-if = " 1.0.0"
17
18
futures = " 0.3.29"
18
19
lazy_static = " 1.4.0"
19
20
tokio-test = " 0.4.3"
20
21
22
+ [dependencies .async-std ]
23
+ version = " 1.12.0"
24
+ optional = true
25
+
26
+ features = [" alloc" ]
21
27
[dependencies .serde ]
22
28
version = " 1.0.190"
23
29
features = [" derive" ]
24
-
25
30
[dependencies .tokio ]
26
31
version = " 1.33.0"
27
- features = [" full" ]
32
+ features = [" rt" , " macros" , " rt-multi-thread" ]
33
+ optional = true
28
34
29
35
[dependencies .uuid ]
30
36
version = " 1.5.0"
31
37
features = [" v4" ]
38
+
39
+ [features ]
40
+ use-async-std = [" async-std" ]
41
+ default = [" tokio" ]
Original file line number Diff line number Diff line change 113
113
License: MIT
114
114
*/
115
115
116
+ use futures:: future:: { BoxFuture , Future , FutureExt } ;
116
117
use serde:: { Deserialize , Serialize } ;
117
118
use std:: { collections:: HashMap , sync:: Arc } ;
118
- use tokio:: task:: { self } ;
119
-
120
- use futures:: future:: { BoxFuture , Future , FutureExt } ;
121
119
use uuid:: Uuid ;
122
120
123
121
pub type AsyncCB = dyn Fn ( Vec < u8 > ) -> BoxFuture < ' static , ( ) > + Send + Sync + ' static ;
@@ -169,14 +167,34 @@ impl AsyncEventEmitter {
169
167
170
168
match listener. limit {
171
169
None => {
172
- callback_handlers. push ( task:: spawn ( async move {
173
- callback ( bytes) . await ;
170
+ cfg_if:: cfg_if! {
171
+ if #[ cfg( feature = "use-async-std" ) ] {
172
+ use async_std:: task:: spawn;
173
+ callback_handlers. push( spawn( async move {
174
+ callback( bytes) . await ;
174
175
} ) ) ;
176
+ } else {
177
+ use tokio:: spawn;
178
+ callback_handlers
179
+ . push( spawn( async move { callback( bytes) . await } ) ) ;
180
+ }
181
+
182
+ } ;
175
183
}
176
184
Some ( limit) => {
177
185
if limit != 0 {
178
- callback_handlers
179
- . push ( task:: spawn ( async move { callback ( bytes) . await } ) ) ;
186
+ cfg_if:: cfg_if! {
187
+ if #[ cfg( feature = "use-async-std" ) ] {
188
+ callback_handlers. push( async_std:: task:: spawn( async move {
189
+ callback( bytes) . await ;
190
+ } ) ) ;
191
+ } else {
192
+ callback_handlers
193
+ . push( tokio:: spawn( async move { callback( bytes) . await } ) ) ;
194
+ }
195
+
196
+ } ;
197
+
180
198
listener. limit = Some ( limit - 1 ) ;
181
199
} else {
182
200
listeners_to_remove. push ( index) ;
@@ -192,7 +210,7 @@ impl AsyncEventEmitter {
192
210
}
193
211
194
212
for handles in callback_handlers {
195
- handles. await ? ;
213
+ handles. await ;
196
214
}
197
215
198
216
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments