| 97 | } |
| 98 | |
| 99 | void StartJob(std::size_t index) |
| 100 | { |
| 101 | cm::uv_timer_ptr& job = this->Jobs[index].Timer; |
| 102 | job.init(*this->Loop, this); |
| 103 | uv_timer_start( |
| 104 | job, |
| 105 | [](uv_timer_t* handle) { |
| 106 | uv_timer_stop(handle); |
| 107 | auto self = static_cast<JobRunner*>(handle->data); |
| 108 | self->FinishJob(); |
| 109 | }, |
| 110 | /*timeout_ms=*/10 * (1 + (index % 3)), /*repeat_ms=*/0); |
| 111 | ++this->ActiveJobs; |
| 112 | std::cerr << " StartJob(" << index |
| 113 | << "): Active jobs: " << this->ActiveJobs << '\n'; |
| 114 | |
| 115 | if (this->ActiveJobs > kTOTAL_TOKENS) { |
| 116 | std::cerr << "Started more than " << kTOTAL_TOKENS << " jobs at once!\n"; |
| 117 | this->Okay = false; |
| 118 | return; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | void QueueJob(std::size_t index) |
| 123 | { |
no test coverage detected