Ensure async/stateful flows are race-free by avoiding overlapping work for the same logical key and by handling events that arrive before the relevant state is ready.

Practical rules:

Example (per-key queue to prevent stale overwrites):

// pseudo-pattern
if let Some(queued) = pending_updates.get_mut(&key) {
    queued.push(update);
    return;
}

pending_updates.insert(key.clone(), Vec::new());
let rules = current_rules.clone();
spawn(async move {
    process_update(update, rules, key.clone()).await
}, move |me, result, ctx| {
    me.apply(result);
    me.drain_pending_updates(&key, ctx); // sequentially process queued updates
});