| 149 | : state_(std::make_shared<State>(std::move(source), std::move(map))) {} |
| 150 | |
| 151 | Future<V> operator()() { |
| 152 | auto future = Future<V>::Make(); |
| 153 | bool should_trigger; |
| 154 | { |
| 155 | auto guard = state_->mutex.Lock(); |
| 156 | if (state_->finished) { |
| 157 | return AsyncGeneratorEnd<V>(); |
| 158 | } |
| 159 | should_trigger = state_->waiting_jobs.empty(); |
| 160 | state_->waiting_jobs.push_back(future); |
| 161 | } |
| 162 | if (should_trigger) { |
| 163 | state_->source().AddCallback(Callback{state_}); |
| 164 | } |
| 165 | return future; |
| 166 | } |
| 167 | |
| 168 | private: |
| 169 | struct State { |