Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Repeated events

Events are once by default. Set multi: true when one entity instance may emit the same event repeatedly.

YAML model

quent: alpha
model: repeated_events

entities:
  Task:
    events:
      started:
        attributes:
          command: string
      progress:
        multi: true
        attributes:
          items_processed: u64
      ended:
        attributes:
          success: bool

Instrumentation API

The same Task handle emits progress more than once. Repeating started or ended on that handle would return an error.

// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#[allow(unused)]
mod instrumentation {
    include!(concat!(env!("OUT_DIR"), "/repeated_events.rs"));
}

use instrumentation::{Context, Noop, RepeatedEvents, Task};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let context = Context::<RepeatedEvents>::try_new(Noop)?;
    let mut task = context.observer::<Task>().handle();

    task.started("compile".to_owned())?;
    // `started` is a once event, so a second call would return an error.
    // task.started("compile".to_owned())?;
    task.progress(64)?;
    task.progress(128)?;
    task.ended(true)?;

    Ok(())
}
Key point

multi: true permits an event to be emitted more than once for an entity.

Check yourself

Why can progress be called repeatedly?

What happens when started is emitted twice on one handle?