Skip to content

Type-Safe deferred method calls #1199

Open
@goatfryed

Description

@goatfryed

I think deferred method calls could be improved. I'd like to propose the introduction of a deferred() helper struct similar to signals() as introduced in #1000

So the following

#[func]
pub fn do_something(&mut self, my_resource: Gd<MyResource>)

could allow to do something like this

//  call method deferred
self.deferred().do_something(my_resource);

// or maybe even async
self.deferred().do_something(my_resource).await;

and would improve the less type-safe and more verbose syntax of

self.base_mut().call_deferred("do_something", &[my_resource.to_variant()])

As I understand it, `#[func]' already tells us, which methods can be deferred, but since visibility of godot and rust is orthogonal, it should require both here.

Maybe this could even integrate with the signals api somehow to make setup of deferred signals less verbose.

Maybe it's just the way I program and that can be improved, but I use a lot of deferred method calls, when processing game state.

Metadata

Metadata

Assignees

Labels

c: engineGodot classes (nodes, resources, ...)featureAdds functionality to the library

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions