godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

asyncio support

Open jkb0o opened this issue 6 years ago • 1 comments

First of all, thank you for the great contribution! Amazing job! One of the most strong Godot features is yielding to signal. Especially yielding to complete signal of GDScriptFunctionState.

It would be amazing to have some asyncio support out of the box

  1. Ability to define virtual methods as async methods:
import asyncio

@expose
class Player(Node2D):
    
    async def _ready(self):
        print("hello")
        await asyncio.sleep(1)
        print("world")
  1. Wrap Godot signals into asyncio.Future at runtime or as part of godot binding
# runtime based wrapping
@expose
class Player(Node2D):

    async def _ready(self):
        print("Hello")
        timer = get_tree().create_timer(2)

        # runtime based wrapping
        await Signal(timer, "timeout")

        # bindings based wrapping
        # timer.timeout here is a getter which returns asyncio.Future
        await timer.timeout
  1. Wrap GDSriptFunctionState into asyncio.Future
@expose
class Player(Node2D):
    def _ready(self):
        await get_node("gdscript").async_method()

I'm looking deeper into it, but I didn't touch python for some years.

jkb0o avatar Feb 17 '19 11:02 jkb0o

One of the most strong Godot features is yielding to signal. Especially yielding to complete signal of GDScriptFunctionState.

I'm currently figuring out a way to do this. Can this be achieved with the current implementation? Use case: I'm trying the "Your first game" tutorial and it makes a yield call to for a timer timeout signal. Is there a workaround you could suggest?

cr8ivecodesmith avatar Jul 20 '20 12:07 cr8ivecodesmith