Verse Library verse

06 Fragment

Uses a race construct to run multiple branches simultaneously and proceeds with whichever finishes first.

verse-library/verse-concurrency-async-race-state-machines/06-fragment.verse

# Wait for the player to press the button, but no longer than 5 seconds.
# Whichever happens first wins; the other is cancelled.
race:
    ButtonPressed.Await()    # arm A: the player acted
    Sleep(5.0)               # arm B: time ran out

Comments

    Sign in to vote, comment, or suggest an edit. Sign in