-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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 await
keyword
#22947
Comments
I'm not sure I understand. |
This is about GDScript, not Python. And this is only about I propose to add some sugar to improve code readability and experience, so:
function wait(t):
yield(get_tree().create_timer(t), "timeout") |
I actually meant to remove that reference to Python before submitting my comment, woops! That being said, while I understand now, I'm not sure I can see this alias being useful enough in game code to warrant being added. I know I've never needed to wait for a FunctionState to emit Consider me neutral on the subject. |
|
@OvermindDL1 GDScript has coroutines already. Any function yielding for a signal is an implicit coroutine. It may be useful to define coroutines explicitly func get_frames_time(num_frames:int):
var time = 0
while num_frames > 0:
time += get_process_delta_time()
num_frames -= 1
yield(get_tree(), "idle_frame")
return time
func _ready():
# I suggest to use
# var time = await get_frames_time(x)
var ten_frames = yield(get_frames_time(10), "completed") # its ok, everything goes as expected
var zero_frames = yield(get_frames_time(0), "completed") # error here, get_frames_time(0) returns 0, can't yield to it
But |
GDScript has scoped coroutines, more similar to Python generators or function-bound coroutines like in C# or recent javascript's or so forth. Unbounded continuations are significantly more useful and powerful, though difficult to implement efficiently. If unbounded coroutines do get implemented then you'd be able to implement a full Effects system within the GDScript language itself though. (Effects as in Algebraic Effects, not game effects. With algebraic effects you could not only implement something like |
@OvermindDL1 why? |
@JJay Hmm? Why what? |
'await func()' seems like a fine idea for shortening the typing and improving readability for end use. As long as it works as expected, I certainly wouldn't mind having it around. |
can await handle functions that don't yield also? This is what I currently do
the reason is I have functions that are only a coroutine if some function executing inside them are coroutines and it'd be nice to just be able to do
|
@LeonardMeagher2 I've run into this problem too, when the the yield is conditional. Not sure if there is a clean or easy way to return a function state without either yielding at the start of the function, or doing what you have in your example. It may need its own issue, since this one is mainly aimed at just creating an alias for how it already works. |
Note: this is being closed as part of our move to GIP, but it is being implemented very soon in #39093. Accordingly, there is no need to reopen a new proposal. :) Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine. The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker. If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance! |
It would be amazing if I could write
var result = await method(arg)
instead ofvar result = yield(method(arg), "completed")
as it highly improves code experience with low cost (no back compat issues, not so difficult to implement, etc.). I assumeasync
to be a be a unary expression likereturn
with onlyFunctionState
possible operand.I'm a big fan of
yield
to signals and have a lot of code likeThis code is harder to write, harder to read then
This is feature proposal/discussion but I'm already on the road of implementing this for local fork.
The text was updated successfully, but these errors were encountered: