(
&self,
mut store: impl AsContextMut<Data = T>,
asyncness: Asyncness,
)
| 1161 | } |
| 1162 | |
| 1163 | async fn _instantiate( |
| 1164 | &self, |
| 1165 | mut store: impl AsContextMut<Data = T>, |
| 1166 | asyncness: Asyncness, |
| 1167 | ) -> Result<Instance> { |
| 1168 | let store = store.as_context_mut(); |
| 1169 | store.0.set_async_required(self.asyncness); |
| 1170 | store |
| 1171 | .engine() |
| 1172 | .allocator() |
| 1173 | .increment_component_instance_count()?; |
| 1174 | |
| 1175 | // Helper structure to pair the above increment with a decrement should |
| 1176 | // anything fail below. |
| 1177 | let mut decrement = DecrementComponentInstanceCountOnDrop { |
| 1178 | store, |
| 1179 | enabled: true, |
| 1180 | }; |
| 1181 | |
| 1182 | let mut instantiator = |
| 1183 | Instantiator::new(&self.component, decrement.store.0, &self.imports)?; |
| 1184 | instantiator.run(&mut decrement.store, asyncness).await?; |
| 1185 | |
| 1186 | let instance = Instance::from_wasmtime(decrement.store.0, instantiator.id); |
| 1187 | decrement.store.0.push_component_instance(instance); |
| 1188 | |
| 1189 | // Everything has passed, don't decrement the instance count and let the |
| 1190 | // destructor for the `Store` handle that at this point. |
| 1191 | decrement.enabled = false; |
| 1192 | return Ok(instance); |
| 1193 | |
| 1194 | struct DecrementComponentInstanceCountOnDrop<'a, T: 'static> { |
| 1195 | store: StoreContextMut<'a, T>, |
| 1196 | enabled: bool, |
| 1197 | } |
| 1198 | |
| 1199 | impl<T> Drop for DecrementComponentInstanceCountOnDrop<'_, T> { |
| 1200 | fn drop(&mut self) { |
| 1201 | if self.enabled { |
| 1202 | self.store |
| 1203 | .engine() |
| 1204 | .allocator() |
| 1205 | .decrement_component_instance_count(); |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | } |
no test coverage detected