deliver method
Delivers a CEP trigger into the Digia engine.
A total function: it never throws, and always returns a handle. A synchronous rejection — unknown key, invalid config, missing anchor — returns an already settled presentation, so the caller has one code path either way.
Returns synchronously, and must keep doing so: the handle is a
receipt, not an answer. The answer arrives later on
CampaignPresentation.outcome. A plugin needs its synchronous grip on
the handle because a CEP can close a template milliseconds after
presenting it — without it, cancel() would be racy and the plugin would
need a side-map to correlate CEP context with a handle that arrives later.
Implementation
@override
CampaignPresentation deliver(CEPTriggerPayload trigger) {
final controller = PresentationController(
id: 'p-${_controllers.length + 1}',
trigger: trigger,
);
_controllers.add(controller);
if (_scripted.isNotEmpty) {
final outcome = _scripted.removeAt(0);
if (outcome is PresentationDismissed) controller.markDisplaying();
controller.settle(outcome);
}
return controller.presentation;
}