Skip to content

Add await() operator

Pedro Ciambra requested to merge github/fork/jabcross/await into master

This is an old implementation that I thought I might leave here.

Here,

_x = await(foo(1))

is equivalent to

_x = foo(1)
if _x is GDScriptFunctionState:
    _x = yield(_x,"completed")

This is useful when the function might or might not yield, but the final result is predictable.

I have used the above pattern very often, particularly when waiting for user input.

This also paves the way for type-checking coroutines, as the return type of await() will never be a FunctionState.

@vnen might be interested!

Merge request reports