You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Porting the official demo projects to 4.0 (see godotengine/godot-demo-projects#747, which is what made me think of this), plus some personal projects. This isn't really specific to a particular type of project, just anything that uses threads.
Describe the problem or limitation you are having in your project
As of the introduction of Callables, Thread.start takes a callable, and it expects the callable to accept exactly one argument, which is passed to the start method in the form of the userdata argument. If the callable is not able to take exactly one argument, it won't work. This makes it annoying to use threads for methods that can't take arguments or that require more than one.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
This made sense before callables, when you instead passed the name of the method as a string. But now, it would make more sense to use Callable.bind to pass arguments. This way, the callable can take any number of arguments.
Thus, I propose removing the userdata argument from Thread.start and having threads not pass any additional arguments.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Instead of calling:
thread.start(_bg_load, "res://mona.png")
we would call:
thread.start(_bg_load.bind("res://mona.png"))
This would have the advantage of allowing no arguments, and making it easier easier to include more than one argument.
Is there a reason why this should be core and not an add-on in the asset library?
This can't be done with an add-on or asset.
The text was updated successfully, but these errors were encountered:
jtnicholl
changed the title
Remove the userdata argument from Thread.start
Remove the userdata argument from Thread.start in favor of using Callable.bind
Jun 18, 2022
Describe the project you are working on
Porting the official demo projects to 4.0 (see godotengine/godot-demo-projects#747, which is what made me think of this), plus some personal projects. This isn't really specific to a particular type of project, just anything that uses threads.
Describe the problem or limitation you are having in your project
As of the introduction of
Callable
s,Thread.start
takes a callable, and it expects the callable to accept exactly one argument, which is passed to the start method in the form of theuserdata
argument. If the callable is not able to take exactly one argument, it won't work. This makes it annoying to use threads for methods that can't take arguments or that require more than one.Describe the feature / enhancement and how it helps to overcome the problem or limitation
This made sense before callables, when you instead passed the name of the method as a string. But now, it would make more sense to use
Callable.bind
to pass arguments. This way, the callable can take any number of arguments.Thus, I propose removing the
userdata
argument fromThread.start
and having threads not pass any additional arguments.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Instead of calling:
we would call:
This would have the advantage of allowing no arguments, and making it easier easier to include more than one argument.
If this enhancement will not be used often, can it be worked around with a few lines of script?
This can be worked around using lambdas, but it's inelegant and shouldn't be necessary.
Is there a reason why this should be core and not an add-on in the asset library?
This can't be done with an add-on or asset.
The text was updated successfully, but these errors were encountered: