Skip to content

Metode Halt ​

Metode halt adalah fungsi kontrol penting yang digunakan untuk segera menghentikan semua eksekusi VM. Metode ini mengakhiri proses saat ini, mencegah instruksi bytecode lebih lanjut diproses.

Menggunakan TypeScript ​

Untuk TypeScript, memanggil metode halt memaksa VM untuk berhenti seketika. Ini berguna untuk penghentian darurat atau ketika logika Anda menentukan bahwa konteks eksekusi saat ini tidak lagi 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.');

Menggunakan 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

Kapabilitas yang Dibutuhkan: Unsafe