mirror of
https://github.com/openai/codex.git
synced 2026-11-13 21:30:47 +00:00
add cloud requirements error msg
This commit is contained in:
@@ -9,6 +9,7 @@ use std::future::Future;
|
||||
pub struct CloudRequirementsLoader {
|
||||
// TODO(gt): This should return a Result once we can fail-closed.
|
||||
fut: Shared<BoxFuture<'static, Option<ConfigRequirementsToml>>>,
|
||||
warning_fut: Option<Shared<BoxFuture<'static, Option<String>>>>,
|
||||
}
|
||||
|
||||
impl CloudRequirementsLoader {
|
||||
@@ -18,12 +19,31 @@ impl CloudRequirementsLoader {
|
||||
{
|
||||
Self {
|
||||
fut: fut.boxed().shared(),
|
||||
warning_fut: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_warning<F, W>(fut: F, warning_fut: W) -> Self
|
||||
where
|
||||
F: Future<Output = Option<ConfigRequirementsToml>> + Send + 'static,
|
||||
W: Future<Output = Option<String>> + Send + 'static,
|
||||
{
|
||||
Self {
|
||||
fut: fut.boxed().shared(),
|
||||
warning_fut: Some(warning_fut.boxed().shared()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get(&self) -> Option<ConfigRequirementsToml> {
|
||||
self.fut.clone().await
|
||||
}
|
||||
|
||||
pub async fn warning(&self) -> Option<String> {
|
||||
match &self.warning_fut {
|
||||
Some(warning_fut) => warning_fut.clone().await,
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for CloudRequirementsLoader {
|
||||
@@ -59,4 +79,18 @@ mod tests {
|
||||
assert_eq!(first, second);
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn shared_warning_future_runs_once() {
|
||||
let counter = Arc::new(AtomicUsize::new(0));
|
||||
let counter_clone = Arc::clone(&counter);
|
||||
let loader = CloudRequirementsLoader::new_with_warning(async { None }, async move {
|
||||
counter_clone.fetch_add(1, Ordering::SeqCst);
|
||||
Some("warning".to_string())
|
||||
});
|
||||
|
||||
let (first, second) = tokio::join!(loader.warning(), loader.warning());
|
||||
assert_eq!(first, second);
|
||||
assert_eq!(counter.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user