The select statement in GDScript allows you to wait on multiple channel operations. Combining threads and channels with select is a powerful feature of GDScript.
We receive the values “one” and then “two” as expected.
Note that the total execution time is only ~2 seconds since both the 1 and 2 second delays execute concurrently.
In this GDScript version:
We use Thread to simulate goroutines.
We implement a simple Channel class to mimic Go’s channels.
We create a custom select function that uses yield to wait for the first channel to receive a value.
Instead of time.Sleep, we use OS.delay_msec for delays.
We use a match statement (similar to Go’s switch) to handle different channel cases.
This implementation provides similar functionality to the original Go code, allowing for concurrent operations and selecting from multiple channels.