Skip to content

Commit bb04e12

Browse files
committed
Fix segfault
1 parent 330fb4f commit bb04e12

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/cpr/async.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ class GlobalThreadPool : public ThreadPool {
2424
**/
2525
template <bool isCancellable = false, class Fn, class... Args>
2626
auto async(Fn&& fn, Args&&... args) {
27-
std::future ret = GlobalThreadPool::GetInstance()->Submit(std::forward<Fn>(fn), std::forward<Args>(args)...);
28-
return AsyncWrapper<decltype(ret.get()), isCancellable>{std::move(ret)};
27+
std::future future = GlobalThreadPool::GetInstance()->Submit(std::forward<Fn>(fn), std::forward<Args>(args)...);
28+
using async_wrapper_t = AsyncWrapper<decltype(future.get()), isCancellable>;
29+
if constexpr (isCancellable) {
30+
return async_wrapper_t{std::move(future), std::make_shared<std::atomic_bool>(false)};
31+
} else {
32+
return async_wrapper_t{std::move(future)};
33+
}
2934
}
3035

3136
class async {

0 commit comments

Comments
 (0)