Why is await breaking the function?

Godot Version

Godot 4.2.1

Question

The first time (in the _ready function) await works without problems and waits for a click, but the second time (in the some_func function) it interrupts the function as return does.

I have a code that looks like this:

signal click

func _ready()
	$Button.connect("button_down",button_click)
	await click
	print("Done 1")
	some_func()
	print("Done 3")

func some_func():
	await click
	print("Done 2")

func button_click():
	click.emit()

The output will only print:

Done 1
Done 3

But “Done 2” is never printed in the output. I suppose await somehow interrupts the function for some reason, but I don’t know why.

Okay, it’s just asynchronized the callable function and _ready()
I just edited the code like this:

signal click

func _ready()
	$Button.connect("button_down",button_click)
	await click
	print("Done 1")
	await some_func()
	print("Done 3")

func some_func():
	await click
	print("Done 2")

func button_click():
	click.emit()

And it works! Maybe because my code is more complex, my button in the previous version cannot be pressed.

BTW, you are calling a function that is async so you must await on the async function call as well.

The compiler is creating “response” handlers, if await is not present, there is no “handler” to return from the fucntion’s await.