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