Skip to content

Commit

Permalink
Better sleep api
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 5, 2023
1 parent 6d8214c commit 2f1fe2b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions coroio/poller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ class TPollerBase {
Changes_.emplace_back(TEvent{fd, TEvent::READ|TEvent::WRITE, {}});
}

template<typename Rep, typename Period>
auto Sleep(std::chrono::duration<Rep,Period> duration) {
auto now = TClock::now();
auto next= now+duration;
auto Sleep(TTime until) {
struct TAwaitable {
bool await_ready() {
return false;
Expand All @@ -63,7 +60,12 @@ class TPollerBase {
TPollerBase* poller;
TTime n;
};
return TAwaitable{this,next};
return TAwaitable{this,until};
}

template<typename Rep, typename Period>
auto Sleep(std::chrono::duration<Rep,Period> duration) {
return Sleep(TClock::now() + duration);
}

void Wakeup(TEvent&& change) {
Expand Down

0 comments on commit 2f1fe2b

Please sign in to comment.