pub struct RecordBatchReceiverStreamBuilder { /* private fields */ }
Expand description
Builder for RecordBatchReceiverStream
that propagates errors
and panic’s correctly.
RecordBatchReceiverStreamBuilder
is used to spawn one or more tasks
that produce RecordBatch
es and send them to a single
Receiver
which can improve parallelism.
This also handles propagating panic`s and canceling the tasks.
§Example
The following example spawns 2 tasks that will write RecordBatch
es to
the tx
end of the builder, after building the stream, we can receive
those batches with calling .next()
let schema = Arc::new(Schema::new(vec![Field::new("foo", DataType::Int8, false)]));
let mut builder = RecordBatchReceiverStreamBuilder::new(Arc::clone(&schema), 10);
// task 1
let tx_1 = builder.tx();
let schema_1 = Arc::clone(&schema);
builder.spawn(async move {
// Your task needs to send batches to the tx
tx_1.send(Ok(RecordBatch::new_empty(schema_1))).await.unwrap();
Ok(())
});
// task 2
let tx_2 = builder.tx();
let schema_2 = Arc::clone(&schema);
builder.spawn(async move {
// Your task needs to send batches to the tx
tx_2.send(Ok(RecordBatch::new_empty(schema_2))).await.unwrap();
Ok(())
});
let mut stream = builder.build();
while let Some(res_batch) = stream.next().await {
// `res_batch` can either from task 1 or 2
// do something with `res_batch`
}
Implementations§
source§impl RecordBatchReceiverStreamBuilder
impl RecordBatchReceiverStreamBuilder
sourcepub fn new(schema: SchemaRef, capacity: usize) -> Self
pub fn new(schema: SchemaRef, capacity: usize) -> Self
create new channels with the specified buffer size
sourcepub fn tx(&self) -> Sender<Result<RecordBatch>>
pub fn tx(&self) -> Sender<Result<RecordBatch>>
Get a handle for sending RecordBatch
to the output
sourcepub fn spawn<F>(&mut self, task: F)
pub fn spawn<F>(&mut self, task: F)
Spawn task that will be aborted if this builder (or the stream built from it) are dropped
This is often used to spawn tasks that write to the sender
retrieved from Self::tx
, for examples, see the document
of this type.
sourcepub fn spawn_blocking<F>(&mut self, f: F)
pub fn spawn_blocking<F>(&mut self, f: F)
Spawn a blocking task that will be aborted if this builder (or the stream built from it) are dropped
This is often used to spawn tasks that write to the sender
retrieved from Self::tx
, for examples, see the document
of this type.
sourcepub fn build(self) -> SendableRecordBatchStream
pub fn build(self) -> SendableRecordBatchStream
Create a stream of all RecordBatch
written to tx
Auto Trait Implementations§
impl Freeze for RecordBatchReceiverStreamBuilder
impl !RefUnwindSafe for RecordBatchReceiverStreamBuilder
impl Send for RecordBatchReceiverStreamBuilder
impl Sync for RecordBatchReceiverStreamBuilder
impl Unpin for RecordBatchReceiverStreamBuilder
impl !UnwindSafe for RecordBatchReceiverStreamBuilder
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