3 ms·
I have plenty of code like that: let id2 = id.clone(); let watch_id2 = watch_id.clone(); let id3 = id.clone(); let watch_id3 = watch_id.clone()
by nemothekid 4y ago
I have plenty of code like that:
let id2 = id.clone();
let watch_id2 = watch_id.clone();
let id3 = id.clone();
let watch_id3 = watch_id.clone();
let ready2 = Arc::downgrade(&ready);
let video_stream = async move {
// use id2, watch_id2, id3, watch_id3, ready2
}
My realization is that in most cases an Arc is the right tool for the job, especially in concurrent applications. I see it as the borrow checker doing it's job, if you have two threads that need to share data and one of them may go away at any moment, the only way you can ensure the memory stays around is with "runtime borrow checking", e.g. a garbage collector.
In C++, the way this is solved is usually "just trust me, I won't use this memory here"