| 343 | } |
| 344 | |
| 345 | pub async fn get_or_create_async<F, Fut>(&mut self, key: String, create_fn: F) -> &Texture2D |
| 346 | where F: FnOnce() -> Fut, |
| 347 | Fut: std::future::Future<Output = Texture2D> |
| 348 | { |
| 349 | if !self.textures.contains_key(&key) { |
| 350 | let texture = create_fn().await; |
| 351 | self.textures.insert(key.clone(), CacheEntry { frames_not_used: 0, owner: texture.into() }); |
| 352 | } |
| 353 | let entry = self.textures.get_mut(&key).unwrap(); |
| 354 | entry.frames_not_used = 0; |
| 355 | entry.owner.texture() |
| 356 | } |
| 357 | |
| 358 | /// Cache a value with the given key. Accepts `Texture2D` or `RenderTarget`. |
| 359 | #[allow(private_bounds)] |