-
-
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
Cannot detect all calls to await
the same way you could with yield
.
#64236
Comments
If Currently in GUT I do this in a number of scenarios script_result = script_inst.call(test_name)
if(_is_function_state(script_result)):
yield(script_result, 'completed') If var call_this = Callable(script_inst, test_name)
call_this.call()
if(call_this.is_awaiting):
await call_this.completed If it only has the flag then you could wait until it finished using var call_this = Callable(script_inst, test_name)
call_this.call()
while(call_this.is_awaiting):
await get_tree().idle_frame I don't think having just the signal will work since it wouldn't be caught if the |
Here is the func _is_function_state(script_result):
return script_result != null and \
typeof(script_result) == TYPE_OBJECT and \
script_result is GDScriptFunctionState and \
script_result.is_valid() |
No progress on this issue? I'm kind of baffled that this isn't at least something you can check on |
In my tests you can use await on a function that itself does no "awaiting". There's no errors and it's as if you didn't try to await on it at all. But if the function actually awaits on something, then the await happens in the call. So, just always use await in this case. It should work. |
This is one thing that I imagined some users would miss (though I didn't see this report until now, sorry) which is essentially manipulating the For Godot 4.0 I purposely remove access to it (it's not even exposed anymore) because while it does have some benefits, it is an implementation detail that users shouldn't care about. More technically, it is a continuation, which is a pretty rare feature in languages AFAIK, and can also get pretty difficult to handle (especially with static types: if a function says it returns I don't mean that this is not an issue. I just think there are better ways to solve this problem, one just being better introspection. Doing this in Callable may be tricky because the the "coroutine" thing is exclusivity of GDScript, so it should not leak out to core types (while other available languages may have it, each have their own implementation which does not translate well to the Godot core API). Unfortunately we're just out of time for 4.0, so this will have to wait a bit longer. In the meantime I wouldn't mind hearing more suggestions or even more use cases so we can find a solution that encompasses them all. PS: Regarding the usage flags you saw when testing, the big number is |
False positive It is impossible to know whether a function is a coroutine or not, but this is more a matter of reflection/introspection in general, and not a limitation when using See also:
|
I think this is now resolved. The original issue seems less significant now (the messages GUT could provide), and nothing else has popped up in the meantime. |
Godot version
v4.0.alpha13.official.59dcddc45
System information
2016 Macbook Pro MacOS 10.15.7
Issue description
In 3.x you could check the return value of a function call to see if a method called
yield
. As far as I can tell, there is no way to do the same in 4.0. The metadata for functions in 4.0 appear to contain a "coroutine" flag if the method callsawait
and contains areturn
. If a method only callsawait
the calling function can't know if anawait
occurred. There are situations when dynamically calling methods where this information is useful, especially when avoiding 'Redundant await' errors.Here's what I've found from testing.
This method has an
await
andreturn
so theusage
flag for the return is 262150This method has an
await
but theusage
value is 6.Use Case
In the GUT unit testing framework you can
yield
(nowawait
) inside a test. In 3.x the framework can detect that ayield
occurred by checking the return value of the method. GUT then yields to the "completed" signal if ayield
occurred. While waiting for the signal, the framework gives animated feedback to the user, letting them know that the test suite has not frozen.In 4.0 it appears that if you
return
within a method that usesawait
it will be marked as a coroutine. This isn't a practical requirement for tests (not your problem, I know) since tests shouldn't return a value. Since we cannot know for sure which tests contain anawait
, all tests must be called withawait
. This will cause a lot "redundant await" errors.Besides the errors, this also prevents the framework from providing feedback to the user that a coroutine was called and it is waiting for it to finish. This can make the test suite appear to hang when it is really waiting for the test to finish.
Workarounds
These are all valid workarounds, but they require action by the end user and extra documentation which end users never read (again, not your problem, I know).
return
when usingawait
.Steps to reproduce
Described in issue description
Minimal reproduction project
Described in issue description.
The text was updated successfully, but these errors were encountered: