Polyphase Game Engine
Loading...
Searching...
No Matches
ControllerServerTypes.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <chrono>
6#include <functional>
7#include <future>
8#include <string>
9
10struct ControllerCommand
11{
12 std::function<std::string()> mFunction;
13 std::promise<std::string> mPromise;
14};
15
16// Bounded wait for a queued command. Returns the result, or a JSON error body
17// if the wait expires. Used by every route handler so a wedged or no-longer-
18// ticking main thread never strands a Crow worker forever (see ControllerServer
19// shutdown notes).
20inline std::string WaitForCommand(std::future<std::string>& f, int timeoutMs = 2000)
21{
22 if (f.wait_for(std::chrono::milliseconds(timeoutMs)) == std::future_status::ready)
23 return f.get();
24 return R"({"error":"timeout","detail":"command did not complete in time"})";
25}
26
27#endif