Skip to content

Instantly share code, notes, and snippets.

@HappyCerberus
Created November 30, 2021 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HappyCerberus/36fdf774ee9a71d1e77ce05f53cc3e86 to your computer and use it in GitHub Desktop.
Save HappyCerberus/36fdf774ee9a71d1e77ce05f53cc3e86 to your computer and use it in GitHub Desktop.
[Article] C++20 Practical Coroutines - scheduler awaiter
struct universal_awaiter {
utils::AwaitableData data_;
std::coroutine_handle<> handle_;
bool await_ready() {
if (!data_.condition)
return false;
bool result = data_.condition();
if (result)
data_.result.result_type = utils::EventType::WakeUp;
return result;
}
std::coroutine_handle<> await_suspend(std::coroutine_handle<> caller) {
data_.continuation = caller;
notify_emitters(&data_);
return handle_;
}
utils::AwaitResult await_resume() { return data_.result; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment