| 217 | |
| 218 | struct Callback { |
| 219 | void operator()(const Result<T>& maybe_next) { |
| 220 | Future<V> sink; |
| 221 | bool end = !maybe_next.ok() || IsIterationEnd(*maybe_next); |
| 222 | bool should_purge = false; |
| 223 | bool should_trigger; |
| 224 | { |
| 225 | auto guard = state->mutex.Lock(); |
| 226 | // A MappedCallback may have purged or be purging the queue; |
| 227 | // we shouldn't do anything here. |
| 228 | if (state->finished) return; |
| 229 | if (end) { |
| 230 | should_purge = !state->finished; |
| 231 | state->finished = true; |
| 232 | } |
| 233 | sink = state->waiting_jobs.front(); |
| 234 | state->waiting_jobs.pop_front(); |
| 235 | should_trigger = !end && !state->waiting_jobs.empty(); |
| 236 | } |
| 237 | if (should_purge) { |
| 238 | state->Purge(); |
| 239 | } |
| 240 | if (should_trigger) { |
| 241 | state->source().AddCallback(Callback{state}); |
| 242 | } |
| 243 | if (maybe_next.ok()) { |
| 244 | const T& val = maybe_next.ValueUnsafe(); |
| 245 | if (IsIterationEnd(val)) { |
| 246 | sink.MarkFinished(IterationTraits<V>::End()); |
| 247 | } else { |
| 248 | Future<V> mapped_fut = state->map(val); |
| 249 | mapped_fut.AddCallback(MappedCallback{std::move(state), std::move(sink)}); |
| 250 | } |
| 251 | } else { |
| 252 | sink.MarkFinished(maybe_next.status()); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | std::shared_ptr<State> state; |
| 257 | }; |
nothing calls this directly
no test coverage detected