File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -245,3 +245,31 @@ impl RuntimeChannel for TokioCurrentThread {
245
245
)
246
246
}
247
247
}
248
+
249
+ /// Runtime implementation for synchronous execution environments.
250
+ ///
251
+ /// This runtime can be used when executing in a non-async environment.
252
+ /// The runtime methods will perform their operations synchronously.
253
+ #[ cfg( feature = "experimental_async_runtime" ) ]
254
+ #[ derive( Debug , Clone , Copy ) ]
255
+ pub struct NoAsync ;
256
+
257
+ #[ cfg( feature = "experimental_async_runtime" ) ]
258
+ impl Runtime for NoAsync {
259
+ fn spawn < F > ( & self , future : F )
260
+ where
261
+ F : Future < Output = ( ) > + Send + ' static ,
262
+ {
263
+ std:: thread:: spawn ( move || {
264
+ futures_executor:: block_on ( future) ;
265
+ } ) ;
266
+ }
267
+
268
+ // Needed because async fn would borrow `self`, violating the `'static` requirement.
269
+ #[ allow( clippy:: manual_async_fn) ]
270
+ fn delay ( & self , duration : Duration ) -> impl Future < Output = ( ) > + Send + ' static {
271
+ async move {
272
+ std:: thread:: sleep ( duration) ;
273
+ }
274
+ }
275
+ }
You can’t perform that action at this time.
0 commit comments