• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jbaldwin / libcoro / 20443437848

22 Dec 2025 08:40PM UTC coverage: 86.774%. First build
20443437848

Pull #430

github

web-flow
Merge 0788332a5 into 1844a5f6f
Pull Request #430: coro:invoke(f, args) for allowing lambda captures in coroutines

6 of 7 new or added lines in 1 file covered. (85.71%)

1719 of 1981 relevant lines covered (86.77%)

5020132.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/include/coro/invoke.hpp
1
#pragma once
2

3
#include <utility>
4

5
namespace coro
6
{
7

8
namespace detail
9
{
10

11
template<typename functor_type, typename... args_types>
12
auto make_invoker_task(functor_type functor, args_types&&... args) -> decltype(functor(std::forward<args_types>(args)...))
4✔
13
{
14
    auto user_task = functor(std::forward<args_types>(args)...);
15
    co_return co_await user_task;
16
}
8✔
17

18
} // namespace detail
19

20
/**
21
 * @brief Invokes the given functor as a coroutine. This is useful if you want
22
 *        to use lambda captures and need them to be captured onto a stable
23
 *        coroutine frame.
24
 *
25
 * @code {.cpp}
26
 * int a = 1;
27
 * int b = 2;
28
 * auto make_task = [&a](int c) -> coro::task<int>
29
 * {
30
 *     co_await task_that_suspends();
31
 *     return a + b;
32
 * }
33
 *
34
 * // This is undefined since &a capture will be dangling.
35
 * co_await make_task(b);
36
 *
37
 * // This is well formed since it will correctly capture on the invoke
38
 * // coroutine frame.
39
 * co_await coro::invoke(make_task, b);
40
 * @endcode
41
 *
42
 *
43
 * @tparam functor_type Functor type.
44
 * @tparam args_types Argument types.
45
 * @param functor The functor to invoke as a coroutine.
46
 * @param args Arguments for functor_type
47
 * @return functor_type -> return_type
48
 */
49
template<typename functor_type, typename... args_types>
50
auto invoke(functor_type functor, args_types&&... args) -> decltype(auto)
4✔
51
{
52
    auto invoker_task = detail::make_invoker_task(std::forward<functor_type>(functor), std::forward<args_types>(args)...);
4✔
53
    invoker_task.resume();
4✔
54
    return invoker_task;
4✔
55

56
    //co_return co_await functor(std::forward<args_types>(args)...);
NEW
57
}
×
58

59
} // namespace coro
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc