Skip to content

Commit

Permalink
Capture functions by reference in registry (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenberry authored Oct 23, 2024
1 parent c12f529 commit d2f4e96
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions include/glaze/rpc/repe/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,9 @@ namespace glz::repe
if constexpr (std::is_invocable_v<Func>) {
using Result = std::decay_t<std::invoke_result_t<Func>>;
if constexpr (std::same_as<Result, void>) {
methods[full_key] = [callback = func, chain = get_chain(full_key)](repe::state&& state) mutable {
methods[full_key] = [&func, chain = get_chain(full_key)](repe::state&& state) mutable {
{
callback();
func();
if (state.notify()) {
return;
}
Expand All @@ -730,13 +730,13 @@ namespace glz::repe
};
}
else {
methods[full_key] = [callback = func, chain = get_chain(full_key)](repe::state&& state) mutable {
methods[full_key] = [&func, chain = get_chain(full_key)](repe::state&& state) mutable {
{
if (state.notify()) {
std::ignore = callback();
std::ignore = func();
return;
}
write_response<Opts>(callback(), state);
write_response<Opts>(func(), state);
}
};
}
Expand All @@ -749,7 +749,7 @@ namespace glz::repe
using Params = glz::tuple_element_t<0, Tuple>;
// using Result = std::invoke_result_t<Func, Params>;

methods[full_key] = [callback = func, chain = get_chain(full_key)](repe::state&& state) mutable {
methods[full_key] = [&func, chain = get_chain(full_key)](repe::state&& state) mutable {
static thread_local std::decay_t<Params> params{};
// no need lock locals
if (read_params<Opts>(params, state) == 0) {
Expand All @@ -758,10 +758,10 @@ namespace glz::repe

{
if (state.notify()) {
std::ignore = callback(params);
std::ignore = func(params);
return;
}
write_response<Opts>(callback(params), state);
write_response<Opts>(func(params), state);
}
};
}
Expand Down

0 comments on commit d2f4e96

Please sign in to comment.