AlmostOnceCell
tkaitchuck opened this issue · comments
As an alternative to #61 or #53
in the case of a no_std environment where lazy initialization is needed, it would be useful to have an implementation which did not block (and hence depend on locking) or spin, but simply re-ran the initialization logic.
So if the initialization has been completed the existing result is used. However if init is attempted from multiple threads concurrently, then it just gets run more than once. For cases where the init is deterministic this provides a clean, zero-dependency, solution.
your wish is granted https://docs.rs/once_cell/1.5.2/once_cell/race/index.html
😀
Well it does look inconsistent with the others. I don't know if there is a reason for that.
Unsync has Lazy
and OnceCell
,
Sync has Lazy
and OnceCell
,
but Race has OnceBox
, OnceNonZeroUsize
and OnceBool
.
OnceBox
appears to be the same as OnceCell
in the others but is not named similarly. (It's docs look copied and pasted and make no mention of races).
Lazy
is missing. I don't know if there is a reason for that. But if not it is useful and would be good to add.
The other two classes I haven't considered as they don't fit my app's needs.