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,
)
| 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) { |
nothing calls this directly
no test coverage detected