Skip to content

Commit b58ab5b

Browse files
author
vtornikita
committed
fix engine: allow task builder acquire move-only args
Tests: utest commit_hash:4cdbd84cd01bd9962884c6939904c9d3bbef76be
1 parent bcb2d10 commit b58ab5b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

core/include/userver/utils/task_builder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ inline auto TaskBuilder::MakeSpanFunctor(
125125

126126
template <typename Function, typename... Args>
127127
auto TaskBuilder::Build(Function&& f, Args&&... args) {
128-
using Task = engine::TaskWithResult<decltype(f(args...))>;
128+
using Task = engine::TaskWithResult<std::invoke_result_t<Function, Args...>>;
129129
return BuildTask<Task>(std::forward<Function>(f), std::forward<Args>(args)...);
130130
}
131131

132132
template <typename Function, typename... Args>
133133
auto TaskBuilder::BuildShared(Function&& f, Args&&... args) {
134-
using Task = engine::SharedTaskWithResult<decltype(f(args...))>;
134+
using Task = engine::SharedTaskWithResult<std::invoke_result_t<Function, Args...>>;
135135
return BuildTask<Task>(std::forward<Function>(f), std::forward<Args>(args)...);
136136
}
137137

core/src/utils/task_builder_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ UTEST(TaskBuilder, Deadline) {
5959
EXPECT_TRUE(task.IsFinished());
6060
}
6161

62+
UTEST(TaskBuilder, ForwardsMoveOnlyType) {
63+
bool task_executed = false;
64+
auto test_function = [&task_executed](std::unique_ptr<int>) { task_executed = true; };
65+
utils::TaskBuilder builder;
66+
67+
auto ptr = std::make_unique<int>(42);
68+
builder.NoSpan().Build(test_function, std::move(ptr)).Get();
69+
70+
EXPECT_TRUE(task_executed);
71+
}
72+
6273
engine::TaskInheritedVariable<int> task_local_variable;
6374

6475
UTEST(TaskBuilder, Background) {

0 commit comments

Comments
 (0)