MCPcopy Create free account
hub / github.com/ccusage/ccusage / get_or_try_load

Method get_or_try_load

rust/crates/ccusage/src/pricing.rs:126–150  ·  view source on GitHub ↗
(&self, fetch_json: F)

Source from the content-addressed store, hash-verified

124 }
125
126 fn get_or_try_load<F>(&self, fetch_json: F) -> Option<&PricingMap>
127 where
128 F: FnOnce() -> std::io::Result<String>,
129 {
130 if let Some(pricing) = self.pricing.get() {
131 return Some(pricing);
132 }
133 if self.last_failure.lock().is_ok_and(|last_failure| {
134 last_failure.is_some_and(|failed_at| failed_at.elapsed() < self.failure_retry_after)
135 }) {
136 return None;
137 }
138
139 let Some(map) = load_models_dev_pricing(fetch_json) else {
140 if let Ok(mut last_failure) = self.last_failure.lock() {
141 *last_failure = Some(Instant::now());
142 }
143 return None;
144 };
145 let _ = self.pricing.set(map);
146 if let Ok(mut last_failure) = self.last_failure.lock() {
147 *last_failure = None;
148 }
149 self.pricing.get()
150 }
151}
152
153#[derive(Debug, Deserialize)]

Calls 2

load_models_dev_pricingFunction · 0.85
setMethod · 0.45