Inspired by the Counter
here: https://webcache.googleusercontent.com/search?q=cache:lJGvIvNiIW0J:https://godotengine.org/qa/147012/join-multiple-coroutines-await-waits-only-single-coroutine&cd=12&hl=en&ct=clnk&gl=uk and Go's WaitGroup
Last active
July 16, 2023 14:19
-
-
Save anthonyec/ba23c921a4dddaaafbb0e08f0385e2ec to your computer and use it in GitHub Desktop.
Wait group for Godot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var animations := WaitGroup.new() | |
for child in get_children(): | |
var tween = child.create_tween() | |
animations.add() | |
tween.connect("finished", animations.done) | |
tween.tween_property(child, "position:x", 10, 1) | |
await animations.finished | |
print("All animations finished!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class_name WaitGroup | |
extends RefCounted | |
signal finished | |
var count: int = 0 | |
func add() -> void: | |
count += 1 | |
func done() -> void: | |
count = clamp(count - 1, 0, INF) | |
if count == 0: | |
finished.emit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment