MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / acquire

Method acquire

nodedb/src/control/planner/wasm/pool.rs:45–64  ·  view source on GitHub ↗

Acquire an instance for the given tenant+function. Takes from pool or creates new.

(
        &self,
        tenant_id: u64,
        func_name: &str,
        module: &Module,
        fuel: u64,
        memory_bytes: usize,
    )

Source from the content-addressed store, hash-verified

43
44 /// Acquire an instance for the given tenant+function. Takes from pool or creates new.
45 pub fn acquire(
46 &self,
47 tenant_id: u64,
48 func_name: &str,
49 module: &Module,
50 fuel: u64,
51 memory_bytes: usize,
52 ) -> crate::Result<PooledInstance> {
53 let key = (tenant_id, func_name.to_string());
54 {
55 let mut pools = self.pools.lock().unwrap_or_else(|p| p.into_inner());
56 if let Some(pool) = pools.get_mut(&key)
57 && let Some(mut inst) = pool.pop()
58 {
59 let _ = inst.store.set_fuel(fuel);
60 return Ok(inst);
61 }
62 }
63 self.create_instance(module, fuel, memory_bytes)
64 }
65
66 /// Return an instance to the pool after use.
67 pub fn release(&self, tenant_id: u64, func_name: &str, instance: PooledInstance) {

Callers

nothing calls this directly

Calls 4

to_stringMethod · 0.80
lockMethod · 0.80
create_instanceMethod · 0.80
get_mutMethod · 0.45

Tested by

no test coverage detected