-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add an @async
annotation
#5893
Comments
I'd prefer a way to switch threads in an async/await context. Something like this:
|
I don't think switching thread while inside a function is possible in GDScript. This also looks unintuitive, at least for me. |
I think Of course, I agree that we should provide a more convenient way to creat a backgound thread without blocking the main thread and can await it to gain it's return value, although it is hard to debug. How about using |
I think the name should be shortened a little |
|
That sounds great |
I am trying to implement it. But don't be too hopeful. |
Wait, I found that we should not await a thread directly, because users may want to abort a thread before finishing. |
I have been working on a proposal that I think might come in handy here: #8752. The idea is a general So instead of @async
func do_something():
# do something heavy You could write @tag("async")
func do_something():
# do something heavy The tag on it's own wouldn't do anything. However, it would signpost to developers that the function should be called asynchronously. This approach is more flexible that trying to design a one-size-fits-all wrapper annotation because how exactly you want to wrap an async function depends pretty heavily on what exactly it's doing and what other processes it might potentially be blocking. |
Describe the project you are working on
N/A
Describe the problem or limitation you are having in your project
In Godot(3 & 4), if you want to await a thread and not block the main thread, you have to do this(syntax depends on engine version):
These repetitive codes can add up if you have to do this even in a few different functions or places.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The
@async
annotation would wrap the function as a coroutine do you couldawait
it.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If this enhancement will not be used often, can it be worked around with a few lines of script?
If this will be implemented in GDScript, then custom annotations will be a minimum requirement.
Is there a reason why this should be core and not an add-on in the asset library?
See above
The text was updated successfully, but these errors were encountered: