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/engine/task_queue_type.hpp>
10#include <userver/utils/function_ref.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace engine {
15
16/// @brief A lightweight TaskProcessor config for engine::RunStandalone
17struct TaskProcessorPoolsConfig final {
18 std::size_t initial_coro_pool_size = 10;
19 std::size_t max_coro_pool_size = 100;
20 std::size_t coro_stack_size = 256 * 1024ULL;
21 std::size_t ev_threads_num = 1;
22 std::string ev_thread_name = "ev";
23 bool ev_default_loop_disabled = false;
24 bool is_stack_usage_monitor_enabled = true;
25 TaskQueueType queue_type{TaskQueueType::kGlobalTaskQueue};
26};
27
28/// @brief Runs a payload in a temporary coroutine engine instance.
29///
30/// Creates a TaskProcessor with specified parameters, executes the payload
31/// in an Async and exits. Mainly designated for async code unit testing.
32///
33/// @warning This function must not be used while another engine instance is
34/// running.
35///
36/// @param payload Code to be run in a Task
37void RunStandalone(utils::function_ref<void()> payload);
38
39/// @overload
40///
41/// @param worker_threads Engine thread pool size, 1 by default
42/// @param payload Code to be run in a Task
43void RunStandalone(std::size_t worker_threads, utils::function_ref<void()> payload);
44
45/// @overload
46///
47/// @param worker_threads Engine thread pool size, 1 by default
48/// @param config A lightweight TaskProcessor config
49/// @param payload Code to be run in a Task
51 std::size_t worker_threads,
52 const TaskProcessorPoolsConfig& config,
53 utils::function_ref<void()> payload
54);
55
56} // namespace engine
57
58USERVER_NAMESPACE_END