Skip to content

Commit

Permalink
Add support for std::future<void> with enqueue
Browse files Browse the repository at this point in the history
Added support for `std::future<void>` return type with `dp::thread_pool::enqueue`.

Fixes #37
  • Loading branch information
DeveloperPaul123 committed Jun 1, 2023
1 parent a442e8b commit ffd1318
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions include/thread_pool/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ namespace dp {
auto task = [func = std::move(f), ... largs = std::move(args),
promise = std::move(promise)]() mutable {
try {
promise.set_value(func(largs...));
if constexpr (std::is_same_v<ReturnType, void>) {
func(largs...);
promise.set_value();
} else {
promise.set_value(func(largs...));
}
} catch (...) {
promise.set_exception(std::current_exception());
}
Expand All @@ -139,7 +144,13 @@ namespace dp {
auto task = [func = std::move(f), ... largs = std::move(args),
promise = shared_promise]() {
try {
promise->set_value(func(largs...));
if constexpr (std::is_same_v<ReturnType, void>) {
func(largs...);
promise->set_value();
} else {
promise->set_value(func(largs...));
}

} catch (...) {
promise->set_exception(std::current_exception());
}
Expand Down

0 comments on commit ffd1318

Please sign in to comment.