pub struct ThreadObjectWriter<'scope, T>{
sender: Sender<T>,
handle: WorkHandle<'scope>,
meter: ProgressBar,
}
Expand description
Write objects in a background thread.
Fields§
§sender: Sender<T>
§handle: WorkHandle<'scope>
§meter: ProgressBar
Implementations§
Source§impl<'scope, T> ThreadObjectWriter<'scope, T>
impl<'scope, T> ThreadObjectWriter<'scope, T>
pub fn wrap<W>( writer: W, ) -> ThreadObjectWriterBuilder<W, impl Send + FnOnce() -> Result<W>>
pub fn bg_open<W, F>(thunk: F) -> ThreadObjectWriterBuilder<W, F>
Source§impl<'scope, T: Send + Sync + 'scope> ThreadObjectWriter<'scope, T>
impl<'scope, T: Send + Sync + 'scope> ThreadObjectWriter<'scope, T>
Sourcepub fn satellite<'a>(&'a self) -> ThreadWriterSatellite<'a, 'scope, T>where
'scope: 'a,
pub fn satellite<'a>(&'a self) -> ThreadWriterSatellite<'a, 'scope, T>where
'scope: 'a,
Create a satellite writer that writes to the same backend as this writer.
Satellites can be used to enable multiple data-generating threads to write to the same thread writer, turning it into a multi-producer, single-consumer writing pipeline. Satellite writers should be finished, and closing them does not finish the original thread writer (it still needs to have ObjectWriter::finish called, typically after all satellites are done, but it calling ObjectWriter::finish while satellites are still active will wait until the satellites have finished and closed their connections to the consumer thread).
Satellites hold a reference to the original thread writer, to discourage keeping them alive after the thread writer has been finished. They work best with std::thread::scope:
let writer = ThreadWriter::new(writer);
scope(|s| {
for i in 0..NTHREADS {
let out = writer.satellite();
s.spawn(move || {
// process and write to out
out.finish().expect("closing writer failed");
})
}
})