Select in AngelScript
Our example demonstrates how to wait on multiple operations using a select-like mechanism. Combining threads and message passing with this feature is a powerful aspect of AngelScript.
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 sleeps execute concurrently.
In this AngelScript version, we’ve simulated the behavior of Go’s select statement using a loop and checking message queues. The thread_create
function is used to spawn new threads, similar to goroutines in Go. The yield()
function is called to allow other threads to run, simulating concurrent execution.
Keep in mind that AngelScript’s threading model may differ from Go’s, and the exact behavior might vary depending on the specific AngelScript implementation and host application.