userver: userver/engine/run_standalone.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 bool is_stack_usage_monitor_enabled = true;
24};
25
26/// @brief Runs a payload in a temporary coroutine engine instance.
27///
28/// Creates a TaskProcessor with specified parameters, executes the payload
29/// in an Async and exits. Mainly designated for async code unit testing.
30///
31/// @warning This function must not be used while another engine instance is
32/// running.
33///
34/// @param payload Code to be run in a Task
35void RunStandalone(utils::function_ref<void()> payload);
36
37/// @see @ref void RunStandalone(utils::function_ref<void()> payload)
38///
39/// @param worker_threads Engine thread pool size, 1 by default
40/// @param payload Code to be run in a Task
41void RunStandalone(std::size_t worker_threads, utils::function_ref<void()> payload);
42
43/// @see @ref void RunStandalone(utils::function_ref<void()> payload)
44///
45/// @param worker_threads Engine thread pool size, 1 by default
46/// @param config A lightweight TaskProcessor config
47/// @param payload Code to be run in a Task
49 std::size_t worker_threads,
50 const TaskProcessorPoolsConfig& config,
51 utils::function_ref<void()> payload
52);
53
54} // namespace engine
55
56USERVER_NAMESPACE_END