feat: add fuel
This commit is contained in:
@@ -74,7 +74,19 @@ fn main() -> Result<()> {
|
||||
"##);
|
||||
let eval_e = SystemTime::now().duration_since(eval_t1).expect("get duration error");
|
||||
println!("+ eval cost: {}ms", eval_e.as_millis());
|
||||
let a = a.expect("error");
|
||||
let a = match a {
|
||||
Ok(a) => a,
|
||||
Err(a) => {
|
||||
let e = format!("{}", a);
|
||||
if e.contains("all fuel consumed by WebAssembly") {
|
||||
println!("all fuel consumed by WebAssembly");
|
||||
} else {
|
||||
println!("{}", a);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
// let a = a.expect("error");
|
||||
let a: Value = match serde_json::from_str(&a) {
|
||||
Ok(a) => a,
|
||||
Err(e) => panic!("ERROR: {}", e),
|
||||
@@ -125,6 +137,7 @@ fn instantiate<I: Default, E: Default, T>(
|
||||
exports: E::default(),
|
||||
},
|
||||
);
|
||||
store.add_fuel(1_000_000_000_u64).ok(); // FUEL
|
||||
let (exports, _instance) = mk_exports(&mut store, &module, &mut linker)?;
|
||||
Ok((exports, store))
|
||||
}
|
||||
@@ -133,6 +146,7 @@ fn default_config() -> Result<Config> {
|
||||
// Create an engine with caching enabled to assist with iteration in this project.
|
||||
let mut config = Config::new();
|
||||
config.cache_config_load_default()?;
|
||||
config.consume_fuel(true); // FUEL
|
||||
// config.debug_info(true);
|
||||
config.wasm_backtrace_details(wasmtime::WasmBacktraceDetails::Enable);
|
||||
Ok(config)
|
||||
|
||||
Reference in New Issue
Block a user