Skip to content

08. Concurrency

Cruz Wootten edited this page Apr 2, 2024 · 1 revision

8.1 Don’t Decorate Functions with Async

  • Avoid decorating <suspends> functions with Async or similar terms.

  • Do:

    DoWork()<suspends>:void
    
  • Don't:

    DoWorkAsync()<suspends>:void
    
  • It’s acceptable to add the Await prefix to a <suspends> function that internally waits on something to happen. This can clarify how an API is supposed to be used.

    AwaitGameEnd()<suspends>:void=
      # Setup other things before awaiting game end…
        GameEndEvent.Await()
    
    OnBegin()<suspends>:void =
        race:
            RunGameLoop()
            AwaitGameEnd()
    
Clone this wiki locally