hello, im having trouble to initialize a static variable only once asynchronously in a test context. this code helps to understand the issue:
// once_cell::OnceCell or std::sync::OnceLock dont work
static FOO: OnceCell<i32> = OnceCell::new();
fn bar(x: i32) {
// function that must be called **only once**
}
async fn get_foo() -> i32 {
if let Some(foo) = FOO.get() {
return foo;
}
let x = big_computation().await;
FOO.set(x).unwrap();
bar(x);
x
}
#[tokio::test]
async fn test1() {
let x = get_foo().await;
// ...
}
#[tokio::test]
async fn test2() {
let x = get_foo().await;
// ...
}
```here, `bar(x);` is called twice, whereas the code in which it's called should be reached only once. how to handle this?
thanks :D