mission_script_event_batch.h 749 B

12345678910111213141516171819202122232425
  1. #pragma once
  2. #include <cstddef>
  3. namespace sunrise::server::activity::mission {
  4. /** Derived events one instance may dispatch per service slice. */
  5. inline constexpr std::size_t kScriptEventBatchLimit = 64;
  6. /**
  7. * Dispatches queued events while `ready` allows it, up to the batch limit. The ready test stops
  8. * at the first asynchronous output, because the callbacks after it must see its committed result.
  9. * @return Events dispatched.
  10. */
  11. template <class Ready, class Dispatch>
  12. std::size_t drain_script_event_batch(Ready ready, Dispatch dispatch) {
  13. std::size_t count = 0;
  14. while (count < kScriptEventBatchLimit && ready()) {
  15. dispatch();
  16. ++count;
  17. }
  18. return count;
  19. }
  20. } // namespace sunrise::server::activity::mission