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 RecordBatches 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 RecordBatches 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
If the stream is dropped / canceled, the sender will be closed and
calling tx().send() will return an error. Producers should stop
producing in this case and return control.
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_on<F>(&mut self, task: F, handle: &Handle)
pub fn spawn_on<F>(&mut self, task: F, handle: &Handle)
Same as Self::spawn but it spawns the task on the provided runtime.
Sourcepub fn spawn_blocking<F>(&mut self, f: F)
pub fn spawn_blocking<F>(&mut self, f: F)
Spawn a blocking task tied to the builder and stream.
§Drop / Cancel Behavior
If this builder (or the stream built from it) is dropped before the task starts, the task is also dropped and will never start execute.
Note: Once the blocking task has started, it will not be forcibly stopped on drop as Rust does not allow forcing a running thread to terminate. The task will continue running until it completes or encounters an error.
Users should ensure that their blocking function periodically checks for
errors calling tx.blocking_send. An error signals that the stream has
been dropped / cancelled and the blocking task should exit.
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_on<F>(&mut self, f: F, handle: &Handle)
pub fn spawn_blocking_on<F>(&mut self, f: F, handle: &Handle)
Same as Self::spawn_blocking but it spawns the blocking task on the provided runtime.
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