emit method
Emit an event. Evaluates every tip whose triggers contain event, in
priority + order, and presents the first eligible one (or a chain of
critical tips).
Emits are serialized: if another emit is mid-presentation, this call waits for it to finish instead of dropping, so two events that fire in the same frame (e.g. a startup tick and a resume tick) won't race.
Returns true if at least one tip was presented.
Implementation
Future<bool> emit(
BuildContext context,
E event,
DiscoveryContext ctx,
) async {
// Wait for any in-flight emit to finish so we serialize cleanly instead
// of silently dropping. Cap attempts to avoid pathological loops.
for (int attempt = 0; attempt < 5 && _inFlight != null; attempt++) {
try {
await _inFlight;
} catch (_) {
// ignore; prior emit errors shouldn't poison this one
}
}
if (!context.mounted) return false;
final completer = Completer<void>();
_inFlight = completer.future;
try {
return await _runEmit(context, event, ctx);
} finally {
completer.complete();
_inFlight = null;
}
}