use std::sync::Arc;
use std::sync::mpsc::sync_channel;
use arrow_schema::Schema;
use pyo3::{Bound, PyAny};
use crate::crossing::_helpers::parser::start_parsers;
use crate::crossing::_helpers::producer::produce;
use crate::crossing::models::{
ByteBudget, CrossingOptions, CrossingStats, ReadContext, TableBatches,
};
pub fn table_batches(
iterable: &Bound<'_, PyAny>,
snapshot: Option<&Bound<'_, PyAny>>,
options: CrossingOptions,
context: ReadContext,
) -> TableBatches {
let (batch_sender, batch_receiver) = sync_channel(0);
let stats = Arc::new(CrossingStats {
budget: ByteBudget::new(options.max_queued_bytes),
..CrossingStats::default()
});
let dispatch = start_parsers(options, batch_sender, &stats, context);
let source = iterable.clone().unbind();
let snapshot = snapshot.map(|snapshot| snapshot.clone().unbind());
let producer_stats = stats.clone();
std::thread::spawn(move || produce((source, snapshot), options, dispatch, producer_stats));
TableBatches {
receiver: batch_receiver,
schema: Schema::empty(),
stats,
finished: false,
}
}