API Reference › Annotations › @OnQuit
annotation

@OnQuit

@OnQuit handler Name { … }

@OnQuit pins a handler to the program's shutdown moment: it runs exactly once as the program exits, after the final frame. Use it for teardown that must happen once — flushing a save, printing a final tally, releasing a host resource. In the lifecycle timeline it runs after every still-live instance's @OnDespawn hook has fired, so the world has already been torn down by the time @OnQuit sees it. It is the boot-time counterpart of @OnStart; add @Public to also emit a program_quit event other modules can hook.

Example

program QuitHook {
  property Score { total: int = 0 }
  model Scoreboard { Score }

  @OnQuit handler ReportFinalScore {                 # runs once at shutdown
    for (Score) in query [Score] { print(Score.total) }
  }

  handler Seed phase Start { spawn Scoreboard { Score { total: 42 } } }

  handler Finish phase Render { quit() }             # triggers shutdown -> prints 42
}
← All symbols