| 53 | } |
| 54 | |
| 55 | void openhd::AsyncHandle::execute_async(const std::string tag, |
| 56 | std::function<void()> runnable) { |
| 57 | auto task = std::make_shared<openhd::AsyncHandle::RunningTask>(); |
| 58 | task->tag = tag; |
| 59 | task->runnable = std::move(runnable); |
| 60 | task->done = false; |
| 61 | task->worker_thread = std::make_shared<std::thread>([task]() { |
| 62 | auto console = openhd::log::get_default(); |
| 63 | console->debug("{} begin", task->tag); |
| 64 | try { |
| 65 | task->runnable(); |
| 66 | } catch (std::exception& ex) { |
| 67 | console->warn("Exception on {},{}", task->tag, ex.what()); |
| 68 | } catch (...) { |
| 69 | console->warn("Unknown Exception on {}", task->tag); |
| 70 | } |
| 71 | console->debug("{} done", task->tag); |
| 72 | task->done = true; |
| 73 | }); |
| 74 | std::lock_guard<std::mutex> lock(m_threads_mutex); |
| 75 | m_tasks.push_back(task); |
| 76 | } |
| 77 | |
| 78 | void openhd::AsyncHandle::execute_command_async(std::string tag, |
| 79 | std::string command) { |