| 61 | // Warning: If the thread pool is stopped then the call will be ignored. |
| 62 | template <typename F, typename... Args> |
| 63 | auto Submit(F && func, Args &&... args) -> std::future<decltype(func(args...))> |
| 64 | { |
| 65 | using ResultType = decltype(func(args...)); |
| 66 | std::packaged_task<ResultType()> task(std::bind(std::forward<F>(func), std::forward<Args>(args)...)); |
| 67 | std::future<ResultType> result(task.get_future()); |
| 68 | { |
| 69 | std::unique_lock lock(m_mutex); |
| 70 | if (m_done) |
| 71 | return {}; |
| 72 | |
| 73 | m_queue.emplace(std::move(task)); |
| 74 | } |
| 75 | m_condition.notify_one(); |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | // Submit work for execution. |
| 80 | // func - task to be performed. |