Gut icon indicating copy to clipboard operation
Gut copied to clipboard

Wait until object is freed

Open WebF0x opened this issue 1 year ago • 1 comments

I think it could be useful. For example, in my game I want to test that when I hit an enemy, then it dies and is freed. But I found it awkward to await on signals on this soon-to-be null object

Before

enemy.set_name('node_name')
enemy.set_linear_velocity(Vector2.LEFT * 1000)

# Have to wait, but it's hard to guess for how long and slows test runs
wait_seconds(10)
# Or create a custom signal just for the test. It works but gives this awkward error message ==> ERROR: Parameter "obj" is null.
await wait_for_signal(enemy.damaged, 10)

assert_freed(enemy, 'node_name')

After

enemy.set_name('node_name')
enemy.set_linear_velocity(Vector2.LEFT * 1000)

await wait_until_freed(enemy, 10)

assert_freed(enemy, 'node_name')

WebF0x avatar Mar 11 '24 03:03 WebF0x

Thanks! Hey let's hold on for this PR until we resolve https://github.com/bitwes/Gut/issues/585, as it might be a more generic solution. I don't have permission for it, but you can mark it as a "draft PR"

WebF0x avatar Apr 27 '24 00:04 WebF0x

Closing in favor of: https://github.com/bitwes/Gut/pull/609

WebF0x avatar May 18 '24 21:05 WebF0x