1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-09-28 10:20:46 +00:00
falk-werner_webfuse-provider/test/webfuse/utils/timeout_watcher.cc

44 lines
660 B
C++
Raw Normal View History

2020-02-20 16:15:13 +00:00
#include "webfuse/utils/timeout_watcher.hpp"
#include <stdexcept>
using std::chrono::milliseconds;
using std::chrono::duration_cast;
using std::chrono::steady_clock;
namespace
{
milliseconds now()
{
return duration_cast<milliseconds>(steady_clock::now().time_since_epoch());
}
}
namespace webfuse_test
{
TimeoutWatcher::TimeoutWatcher(milliseconds timeout)
: startedAt(now())
, timeout_(timeout)
{
}
TimeoutWatcher::~TimeoutWatcher()
{
}
bool TimeoutWatcher::isTimeout()
{
return (now() - startedAt) > timeout_;
}
void TimeoutWatcher::check()
{
if (isTimeout())
{
throw std::runtime_error("timeout");
}
}
}