Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the userdata argument from Thread.start in favor of using Callable.bind #4691

Closed
jtnicholl opened this issue Jun 18, 2022 · 0 comments · Fixed by godotengine/godot#62326
Labels
breaks compat Proposal will inevitably break compatibility topic:core
Milestone

Comments

@jtnicholl
Copy link

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 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.

thread1.start(_no_argument_function)
thread2.start(_three_argument_function.bind(arg1, arg2, arg3))

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.

thread1.start(func(_unused): _no_arument_function())
thread2.start(func(_unused): _three_argument_function(arg1, arg2, arg3))

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.

@jtnicholl 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
@Calinou Calinou added this to the 4.0 milestone Jun 18, 2022
@Calinou Calinou added the breaks compat Proposal will inevitably break compatibility label Jun 18, 2022
TechnoPorg added a commit to TechnoPorg/godot-docs that referenced this issue Oct 24, 2022
The threading API has changed from Godot 3 -> Godot 4.
See godotengine/godot-proposals#4691.
TechnoPorg added a commit to TechnoPorg/godot that referenced this issue Oct 24, 2022
The threading API has changed between Godot 3 and Godot 4.
See godotengine/godot-proposals#4691.
Yona-W pushed a commit to Yona-W/godot that referenced this issue Oct 30, 2022
The threading API has changed between Godot 3 and Godot 4.
See godotengine/godot-proposals#4691.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks compat Proposal will inevitably break compatibility topic:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants