| 41 | namespace acero { |
| 42 | |
| 43 | AsyncGenerator<std::optional<ExecBatch>> MakeDelayedGen( |
| 44 | Iterator<std::optional<ExecBatch>> src, std::string label, double delay_sec, |
| 45 | bool noisy) { |
| 46 | struct DelayedIoGenState { |
| 47 | DelayedIoGenState(Iterator<std::optional<ExecBatch>> batch_it, double delay_sec, |
| 48 | std::string label, bool noisy) |
| 49 | : batch_it(std::move(batch_it)), |
| 50 | delay_sec(delay_sec), |
| 51 | label(std::move(label)), |
| 52 | noisy(noisy) {} |
| 53 | std::optional<ExecBatch> Next() { |
| 54 | Result<std::optional<ExecBatch>> opt_batch_res = batch_it.Next(); |
| 55 | if (!opt_batch_res.ok()) { |
| 56 | return std::nullopt; |
| 57 | } |
| 58 | std::optional<ExecBatch> opt_batch = opt_batch_res.ValueOrDie(); |
| 59 | if (!opt_batch) { |
| 60 | return std::nullopt; |
| 61 | } |
| 62 | if (noisy) { |
| 63 | std::cout << label + ": asking for batch(" + std::to_string(index) + ")\n"; |
| 64 | } |
| 65 | SleepFor(delay_sec); |
| 66 | ++index; |
| 67 | return *opt_batch; |
| 68 | } |
| 69 | |
| 70 | Iterator<std::optional<ExecBatch>> batch_it; |
| 71 | double delay_sec; |
| 72 | std::string label; |
| 73 | bool noisy; |
| 74 | std::size_t index = 0; |
| 75 | }; |
| 76 | auto state = std::make_shared<DelayedIoGenState>(std::move(src), delay_sec, |
| 77 | std::move(label), noisy); |
| 78 | return [state]() { |
| 79 | return DeferNotOk(::arrow::io::default_io_context().executor()->Submit( |
| 80 | [state]() { return state->Next(); })); |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | AsyncGenerator<std::optional<ExecBatch>> MakeDelayedGen( |
| 85 | AsyncGenerator<std::optional<ExecBatch>> src, std::string label, double delay_sec, |
no test coverage detected