adjust subxt signer static once locks

This commit is contained in:
Tadeo hepperle
2024-02-14 15:51:34 +01:00
parent 2b38a0fce1
commit 64987fe44c
4 changed files with 28 additions and 39 deletions
+21 -6
View File
@@ -17,10 +17,19 @@
macro_rules! once_static {
($($(#[$attr:meta])* $vis:vis fn $name:ident() -> $ty:ty { $expr:expr } )+) => {
$(
$(#[$attr])*
$vis fn $name() -> &'static $ty {
static VAR: once_cell::sync::OnceCell<$ty> = once_cell::sync::OnceCell::new();
VAR.get_or_init(|| { $expr })
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
$(#[$attr])*
$vis fn $name() -> &'static $ty {
static VAR: std::sync::OnceLock<$ty> = std::sync::OnceLock::new();
VAR.get_or_init(|| { $expr })
}
} else {
$(#[$attr])*
$vis fn $name() -> $ty {
$expr
}
}
}
)+
};
@@ -33,8 +42,14 @@ macro_rules! once_static_cloned {
$(
$(#[$attr])*
$vis fn $name() -> $ty {
static VAR: once_cell::sync::OnceCell<$ty> = once_cell::sync::OnceCell::new();
VAR.get_or_init(|| { $expr }).clone()
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
static VAR: std::sync::OnceLock<$ty> = std::sync::OnceLock::new();
VAR.get_or_init(|| { $expr }).clone()
} else {
{ $expr }
}
}
}
)+
};