#include #include #include namespace exe::coroutine { CoroutineImpl::CoroutineImpl(Routine routine, wheels::MutableMemView stack) : routine_(std::move(routine)) { coroutine_context_.Setup(stack, this); } void CoroutineImpl::Run() { try { routine_(); } catch (...) { exception_ptr_ = std::current_exception(); } is_complete_ = true; coroutine_context_.SwitchTo(save_previous_context_); abort(); } void CoroutineImpl::Resume() { save_previous_context_.SwitchTo(coroutine_context_); if (exception_ptr_) { rethrow_exception(exception_ptr_); } } void CoroutineImpl::Suspend() { coroutine_context_.SwitchTo(save_previous_context_); } bool CoroutineImpl::IsCompleted() const { return is_complete_; } } // namespace exe::coroutine