Halt Method
The halt method is a critical control function used to immediately cease all VM execution. It terminates the current process, preventing any further bytecode instructions from being processed.
Using TypeScript
For TypeScript, invoking the halt method forces the VM to stop instantly. This is useful for emergency shutdowns or when your logic determines that the current execution context is no longer valid.
ts
import { Capability, LightVM } from 'lightvm';
const vm = new LightVM({ caps: [Capability.Unsafe] });
vm.halt();
vm.run(); // will not be executed
console.log('The VM has been terminated.');Using Rust
In Rust, the halt method provides a direct way to terminate the VM instance. Once called, the VM will stop executing, ensuring that no subsequent instructions or queued tasks are performed.
rust
use lightvm::LightVM;
use lightvm::types::{capability::Capability, vmconfig::VmConfig};
fn main() {
let mut vm = LightVM::new(VmConfig {
caps: vec![Capability::Unsafe],
..Default::default()
});
vm.halt();
vm.run(None); // will not be executed
println!("The VM has been terminated.");
}INFO
Capability Required: Unsafe