Skip to content

On Method Nightly

The on method is the event-driven heart of LightVM, allowing you to hook into specific VM lifecycle events. By registering callbacks, you can react to internal state changes and execution milestones in real-time.

Using TypeScript

For TypeScript, the on method allows you to attach event listeners that execute whenever a registered event is triggered. This is ideal for logging, monitoring VM state changes, or triggering external logic when specific conditions are met.

ts
vm.on('halt', (payload) => {
  console.log('Halted: ', payload);
});

Using Rust

In Rust, the on method enables you to define event handlers that integrate directly with your system's logic. This allows for robust asynchronous notification when the VM enters a certain state, such as halting or encountering an error.

rust
vm.on("halt", |payload| {
  println!("Halted: {:?}", payload);
});

INFO

Capability Required: no specific capability

Owned Events: tick, halt, and panic

Released under the Apache-2.0 License.