基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sleep.cpp 464B

1234567891011121314151617181920
  1. #include "librf/librf.h"
  2. namespace librf
  3. {
  4. LIBRF_API future_t<> sleep_until_(std::chrono::system_clock::time_point tp_, scheduler_t& scheduler_)
  5. {
  6. awaitable_t<> awaitable;
  7. (void)scheduler_.timer()->add(tp_,
  8. [awaitable](bool cancellation_requested)
  9. {
  10. if (cancellation_requested)
  11. awaitable.throw_exception(canceled_exception{ error_code::timer_canceled });
  12. else
  13. awaitable.set_value();
  14. });
  15. return awaitable.get_future();
  16. }
  17. }