diff --git a/include/ircd/ctx/async.h b/include/ircd/ctx/async.h index 13a19af58..7f8c8404d 100644 --- a/include/ircd/ctx/async.h +++ b/include/ircd/ctx/async.h @@ -60,15 +60,17 @@ ircd::ctx::async(F&& f, { using R = typename std::result_of::type; - auto func(std::bind(std::forward(f), std::forward(a)...)); - auto p(std::make_shared>()); - auto wrapper([p, func(std::move(func))] - () mutable -> void + promise p; + future ret{p}; + auto wrapper { - p->set_value(func()); - }); + [p(std::move(p)), func(std::bind(std::forward(f), std::forward(a)...))] + () mutable + { + p.set_value(func()); + } + }; - future ret(*p); //TODO: DEFER_POST? context(stack_size, std::move(wrapper), context::DETACH | context::POST | flags); return ret; @@ -84,16 +86,23 @@ ircd::ctx::async(F&& f, { using R = typename std::result_of::type; - auto func(std::bind(std::forward(f), std::forward(a)...)); - auto p(std::make_shared>()); - auto wrapper([p, func(std::move(func))] - () mutable -> void + auto func { - func(); - p->set_value(); - }); + std::bind(std::forward(f), std::forward(a)...) + }; + + promise p; + future ret{p}; + auto wrapper + { + [p(std::move(p)), func(std::bind(std::forward(f), std::forward(a)...))] + () mutable + { + func(); + p.set_value(); + } + }; - future ret(*p); //TODO: DEFER_POST? context(stack_size, std::move(wrapper), context::DETACH | context::POST | flags); return ret;