| 47 | } |
| 48 | |
| 49 | void TResourceConstrainedExecutor::ExecTasks() { |
| 50 | while (!Queue.empty()) { |
| 51 | TVector<std::function<void()>> tasks; |
| 52 | |
| 53 | TResourceUnit freeResource = ResourceQuota; |
| 54 | |
| 55 | while (true) { |
| 56 | auto it = Queue.lower_bound(freeResource); |
| 57 | if (it == Queue.end()) { |
| 58 | break; |
| 59 | } |
| 60 | |
| 61 | freeResource -= it->first; |
| 62 | tasks.push_back(std::move(it->second)); |
| 63 | Queue.erase(it); |
| 64 | }; |
| 65 | |
| 66 | if (LenientMode && tasks.empty()) { |
| 67 | // execute at least one task even if it requests more than ResourceQuota |
| 68 | auto it = Queue.begin(); |
| 69 | tasks.push_back(std::move(it->second)); |
| 70 | Queue.erase(it); |
| 71 | } else { |
| 72 | Y_ASSERT(!tasks.empty()); |
| 73 | } |
| 74 | |
| 75 | ExecuteTasksInParallel(&tasks, &LocalExecutor); |
| 76 | } |
| 77 | } |
| 78 | } |
no test coverage detected