| 397 | template <bool cooperative> |
| 398 | template <typename Runnable> |
| 399 | std::enable_if_t<std::is_convertible_v<Runnable, std::function<void()>>> |
| 400 | IncrementalJobImpl<cooperative>::AddTask(Runnable &&runnable) { |
| 401 | if (this->wait_started_) |
| 402 | throw std::logic_error("This job has already been waited for - cannot add more tasks to it"); |
| 403 | |
| 404 | auto it = tasks_.emplace(tasks_.end(), Task()); |
| 405 | try { |
| 406 | it->func = [this, task = &*it, f = std::move(runnable)]() noexcept { |
| 407 | try { |
| 408 | f(); |
| 409 | } catch (...) { |
| 410 | task->error = std::current_exception(); |
| 411 | } |
| 412 | |
| 413 | if (--this->num_pending_tasks_ == 0) |
| 414 | this->DoNotify(); |
| 415 | }; |
| 416 | this->total_tasks_++; |
| 417 | } catch (...) { // if, for whatever reason, we cannot initialize the task, we should erase it |
| 418 | tasks_.erase(it); |
| 419 | throw; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | template <bool cooperative> |
| 424 | template <typename Executor> |