File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 5
5
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- use godot:: classes:: { Engine , Node , Os } ;
8
+ use godot:: classes:: { Engine , Node , Os , SceneTree } ;
9
9
use godot:: obj:: Gd ;
10
10
use godot:: sys;
11
11
use std:: collections:: HashSet ;
@@ -254,6 +254,27 @@ pub fn expect_debug_panic_or_release_ok(_context: &str, code: impl FnOnce()) {
254
254
code ( )
255
255
}
256
256
257
+ /// Run code asynchronously, immediately before the next _process_ frame.
258
+ ///
259
+ /// Useful for assertions that run expect a `call_deferred()` or similar operation, and still want to check the result.
260
+ #[ cfg( since_api = "4.2" ) ]
261
+ #[ must_use]
262
+ #[ allow( dead_code) ] // not yet used.
263
+ pub fn next_frame < F > ( code : F ) -> godot:: task:: TaskHandle
264
+ where
265
+ F : FnOnce ( ) + ' static ,
266
+ {
267
+ let tree = Engine :: singleton ( )
268
+ . get_main_loop ( )
269
+ . unwrap ( )
270
+ . cast :: < SceneTree > ( ) ;
271
+
272
+ godot:: task:: spawn ( async move {
273
+ let _: ( ) = tree. signals ( ) . process_frame ( ) . to_future ( ) . await ;
274
+ code ( ) ;
275
+ } )
276
+ }
277
+
257
278
/// Synchronously run a thread and return result. Panics are propagated to caller thread.
258
279
#[ track_caller]
259
280
pub fn quick_thread < R , F > ( f : F ) -> R
@@ -262,7 +283,6 @@ where
262
283
R : Send + ' static ,
263
284
{
264
285
let handle = std:: thread:: spawn ( f) ;
265
-
266
286
match handle. join ( ) {
267
287
Ok ( result) => result,
268
288
Err ( panic_payload) => {
You can’t perform that action at this time.
0 commit comments