coro/corotaskpromise.hpp

The following code example is taken from the book
C++20 - The Complete Guide by Nicolai M. Josuttis, Leanpub, 2021
The code is licensed under a Creative Commons Attribution 4.0 International License. Creative Commons License

// raw code

struct CoroTask::promise_type {
  auto get_return_object() {       // init and return the coroutine interface
    return CoroTask{CoroHdl::from_promise(*this)};
  }
  auto initial_suspend() {         // initial suspend point
    return std::suspend_always{};  // - suspend immediately
  }
  void unhandled_exception() {     // deal with exceptions
    std::terminate();              // - terminate the program
  }
  void return_void() {             // deal with the end or co_return;
  }
  auto final_suspend() noexcept {  // final suspend point
    return std::suspend_always{};  // - suspend immediately
  }
};