Verse Library verse

03 Fragment

Multiple independent systems subscribe to a shared event to avoid tight coupling.

verse-library/verse-events-decoupling/03-fragment.verse

OnBegin<override>()<suspends> : void =
        RoundTimer.SuccessEvent.Subscribe(OnTimerDone)
        # Each system listens for the round ending, independently.
        RoundEndedEvent.Subscribe(OnUpdateScoreboard)
        RoundEndedEvent.Subscribe(OnPlayVictoryMusic)
        RoundEndedEvent.Subscribe(OnRestockLoot)

    OnUpdateScoreboard() : void =
        Print("Scoreboard updated.")

    OnPlayVictoryMusic() : void =
        Print("Victory music!")

    OnRestockLoot() : void =
        Print("Loot restocked.")

Comments

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