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 bool defer_events = 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
35/// @param worker_threads Engine thread pool size, 1 by default
36/// @param config A lightweight TaskProcessor config
37void RunStandalone(utils::function_ref<void()> payload);
38
39/// @overload
40void RunStandalone(std::size_t worker_threads,
41 utils::function_ref<void()> payload);
42
43/// @overload
44void RunStandalone(std::size_t worker_threads,
45 const TaskProcessorPoolsConfig& config,
46 utils::function_ref<void()> payload);
47
48} // namespace engine
49
50USERVER_NAMESPACE_END