Found an example of overriding co_await
operator and was able to implement my own version:
#include <chrono>
#include <coroutine>
//QTimer::singleShot accepts only milliseconds and a template version of the operator does not compile.
auto operator co_await(std::chrono::milliseconds d)
{
class awaiter
{
std::chrono::milliseconds m_d;
public:
explicit awaiter(std::chrono::milliseconds d) : m_d(d) {}
bool await_ready() const noexcept
{
return m_d <= std::chrono::milliseconds(0);
}
void await_suspend(std::coroutine_handle<> h) const noexcept
{
QTimer::singleShot(m_d, [h]() -> void
{
h.resume();
});
}
void await_resume() const noexcept {}
};
return awaiter { d };
}
For those who did not work with QT, QTimer::singleShot
simply calls the lambda on the current thread after a given interval.