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");
})
}
})
Trait Implementations§
Source§impl<'scope, T: Send + Sync + 'static> ObjectWriter<T> for ThreadObjectWriter<'scope, T>
impl<'scope, T: Send + Sync + 'static> ObjectWriter<T> for ThreadObjectWriter<'scope, T>
Source§fn write_object(&mut self, object: T) -> Result<()>
fn write_object(&mut self, object: T) -> Result<()>
Source§fn write_all_objects<I>(&mut self, objects: I) -> Result<usize>where
I: Iterator<Item = T>,
fn write_all_objects<I>(&mut self, objects: I) -> Result<usize>where
I: Iterator<Item = T>,
Auto Trait Implementations§
impl<'scope, T> Freeze for ThreadObjectWriter<'scope, T>
impl<'scope, T> !RefUnwindSafe for ThreadObjectWriter<'scope, T>
impl<'scope, T> Send for ThreadObjectWriter<'scope, T>
impl<'scope, T> Sync for ThreadObjectWriter<'scope, T>
impl<'scope, T> Unpin for ThreadObjectWriter<'scope, T>
impl<'scope, T> !UnwindSafe for ThreadObjectWriter<'scope, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more