Closed blp closed 1 month ago
I think the original thought was that it's not really meant to be used for anything except tests, where cloning it would be... I don't know why you would ever have to clone it in a test, basically.
There's no technical reason it can't be Clone
, but what's the usecase here?
I have multiple tests, so I used a OnceLock
to make a globally accessible Snapshotter
so that I could use it from all of them, and then I discovered that I couldn't clone it.
For now, I just wrapped Snapshotter
in another Arc
, which also works OK.
A better approach (IMO) would be to use with_local_recorder
, which is designed specifically for tests in order to avoid having to do tricks with a global recorder.
I assumed that with_local_recorder
wouldn't work with additional threads spawned by the test (but I haven't tried it).
Ah, yeah, it wouldn't work for anything other than the thread that with_local_recorder
is called on.
In that case, would be happy to review a PR adding Clone
to Snapshotter
.
Oh, woops! Just realized this will be implemented once #472 is released.
Oh, woops! Just realized this will be implemented once #472 is released.
Oh, perfect, thank you!
Late response, but: this was released in metrics-util@v0.17.0
.
Snapshotter
is just a wrapper around anArc
and I don't know why it can't beClone
d. I suspect it's just an oversight. It would be convenient to make it easy to pass it around multiple places.