| 1048 | Result<std::shared_ptr<Table>> Read() override { return ReadAsync().result(); } |
| 1049 | |
| 1050 | Future<std::shared_ptr<Table>> ReadAsync() override { |
| 1051 | // Note that this task group doesn't survive our destruction, so it's essential |
| 1052 | // that async callbacks own a strong ref to us. |
| 1053 | task_group_ = TaskGroup::MakeThreaded(cpu_executor_, io_context_.stop_token()); |
| 1054 | |
| 1055 | auto self = shared_from_this(); |
| 1056 | return ProcessFirstBuffer().Then([self](const std::shared_ptr<Buffer>& first_buffer) { |
| 1057 | auto block_generator = ThreadedBlockReader::MakeAsyncIterator( |
| 1058 | self->buffer_generator_, MakeChunker(self->parse_options_), first_buffer, |
| 1059 | self->read_options_.skip_rows_after_names); |
| 1060 | |
| 1061 | std::function<Status(CSVBlock)> block_visitor = |
| 1062 | [self](CSVBlock maybe_block) -> Status { |
| 1063 | // The logic in VisitAsyncGenerator ensures that we will never be |
| 1064 | // passed an empty block (visit does not call with the end token) so |
| 1065 | // we can be assured maybe_block has a value. |
| 1066 | DCHECK_GE(maybe_block.block_index, 0); |
| 1067 | DCHECK(!maybe_block.consume_bytes); |
| 1068 | |
| 1069 | // Launch parse task |
| 1070 | self->task_group_->Append( |
| 1071 | [self, maybe_block] { return self->ParseAndInsert(maybe_block); }); |
| 1072 | return Status::OK(); |
| 1073 | }; |
| 1074 | |
| 1075 | return VisitAsyncGenerator(std::move(block_generator), block_visitor) |
| 1076 | .Then([self]() -> Future<> { |
| 1077 | // By this point we've added all top level tasks so it is safe to call |
| 1078 | // FinishAsync |
| 1079 | return self->task_group_->FinishAsync(); |
| 1080 | }) |
| 1081 | .Then([self]() -> Result<std::shared_ptr<Table>> { |
| 1082 | // Finish conversion, create schema and table |
| 1083 | return self->MakeTable(); |
| 1084 | }); |
| 1085 | }); |
| 1086 | } |
| 1087 | |
| 1088 | protected: |
| 1089 | Future<std::shared_ptr<Buffer>> ProcessFirstBuffer() { |
nothing calls this directly
no test coverage detected