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 55 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
66 */
77
8- use godot:: classes:: { Engine , Node , Os } ;
8+ use godot:: classes:: { Engine , Node , Os , SceneTree } ;
99use godot:: obj:: Gd ;
1010use godot:: sys;
1111use std:: collections:: HashSet ;
@@ -254,6 +254,27 @@ pub fn expect_debug_panic_or_release_ok(_context: &str, code: impl FnOnce()) {
254254 code ( )
255255}
256256
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+
257278/// Synchronously run a thread and return result. Panics are propagated to caller thread.
258279#[ track_caller]
259280pub fn quick_thread < R , F > ( f : F ) -> R
@@ -262,7 +283,6 @@ where
262283 R : Send + ' static ,
263284{
264285 let handle = std:: thread:: spawn ( f) ;
265-
266286 match handle. join ( ) {
267287 Ok ( result) => result,
268288 Err ( panic_payload) => {
You can’t perform that action at this time.
0 commit comments