From 0049ba92e66aa55d11d653ff2bfcdd91ed9735ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Thu, 7 Nov 2019 11:51:44 -0500 Subject: [PATCH] thread pool: retransmit exception through future --- include/opendht/thread_pool.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/opendht/thread_pool.h b/include/opendht/thread_pool.h index c8486fd7..1050f101 100644 --- a/include/opendht/thread_pool.h +++ b/include/opendht/thread_pool.h @@ -43,9 +43,15 @@ public: template std::future get(std::function&& cb) { auto ret = std::make_shared>(); - run(std::bind([=](std::function& mcb) mutable { - ret->set_value(mcb()); - }, std::move(cb))); + run([cb = std::move(cb), ret]() mutable { + try { + ret->set_value(cb()); + } catch (...) { + try { + ret->set_exception(std::current_exception()); + } catch(...) {} + } + }); return ret->get_future(); } template