userver: userver/engine/run_standalone.hpp Source File
Loading...
Searching...
No Matches
run_standalone.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/engine/run_standalone.hpp
4/// @brief @copybrief engine::RunStandalone
5
6#include <cstddef>
7#include <string>
8
9#include <userver/utils/function_ref.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace engine {
14
15/// @brief A lightweight TaskProcessor config for engine::RunStandalone
16struct TaskProcessorPoolsConfig final {
17 std::size_t initial_coro_pool_size = 10;
18 std::size_t max_coro_pool_size = 100;
19 std::size_t coro_stack_size = 256 * 1024ULL;
20 std::size_t ev_threads_num = 1;
21 std::string ev_thread_name = "ev";
22 bool ev_default_loop_disabled = false;
23};
24
25/// @brief Runs a payload in a temporary coroutine engine instance.
26///
27/// Creates a TaskProcessor with specified parameters, executes the payload
28/// in an Async and exits. Mainly designated for async code unit testing.
29///
30/// @warning This function must not be used while another engine instance is
31/// running.
32///
33/// @param payload Code to be run in a Task
34/// @param worker_threads Engine thread pool size, 1 by default
35/// @param config A lightweight TaskProcessor config
36void RunStandalone(utils::function_ref<void()> payload);
37
38/// @overload
39void RunStandalone(std::size_t worker_threads, utils::function_ref<void()> payload);
40
41/// @overload
43 std::size_t worker_threads,
44 const TaskProcessorPoolsConfig& config,
45 utils::function_ref<void()> payload
46);
47
48} // namespace engine
49
50USERVER_NAMESPACE_END