admit method
The one admission point for every play request. A non-direct trigger
only renders a teaser, so only a direct trigger can be busy — and a live
test never is, since its open replaces the visible game. On AdmitOpen
the direct and per-campaign guards stay held until request's finally
releases them, so an admitted request always pairs with exactly one
release.
Implementation
AdmitDecision admit({
required String campaignKey,
required bool direct,
required bool testSend,
required bool Function() isGameBusy,
}) {
// A game on screen blocks only a direct open: an inline or floating
// trigger only renders a teaser, so it still asks for its chance.
if (direct && !testSend && isGameBusy()) {
_log.d('Gamification chance not requested — a game is already showing',
campaign: campaignKey);
return const AdmitBusy();
}
if (direct && !testSend && _directInFlight) {
_log.d('Gamification chance not requested — a direct grant is in flight',
campaign: campaignKey);
return const AdmitBusy();
}
if (direct && !testSend) _directInFlight = true;
if (!_inFlight.add(campaignKey)) {
if (direct && !testSend) _directInFlight = false;
_log.d(
'Gamification chance not requested — a request is already in flight',
campaign: campaignKey);
return const AdmitBusy();
}
return const AdmitOpen();
}