I have a C++ class that spawns a thread that contains an event loop of sorts and the class provides an API to query the list of events that have occurred since the last call, i.e something like
In case some sort of fatal error occurs in the event loop, I shut it down and log an error. I'm trying to figure out how this
getEvents() API should communicate that the event loop is no longer running and that it won't return valid output.
Unfortunately, I'm working in an environment where exceptions are disabled so I'm not sure of the best way to handle this. I thought of adding a separate API so the client can query whether or not the event loop is still running but that seemed racy and not ideal.
What's a good approach for designing this?
Update: I think
std::optional in C++17 is the best option.