Skip to content

Commit

Permalink
No graceful exception exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbrq committed Oct 19, 2023
1 parent 6208b5d commit 92e3b34
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
2 changes: 0 additions & 2 deletions include/cxxdes/core/impl/await_transform.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ struct awaitable_wrapper {
}

auto await_resume() {
if (coro_data_this->stopped())
throw coroutine_data::stopped_exception{};
return a.await_resume();
}
};
Expand Down
4 changes: 0 additions & 4 deletions include/cxxdes/core/impl/coroutine.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ public:
try {
std::rethrow_exception(std::current_exception());
}
catch (coroutine_data::stopped_exception &) {
// do nothing, we do not need to propagate this exception
// other coroutines will be also stopped by the environment
}
catch (...) {
// update completion tokens with the current exception
coro_data->propagate_exception(std::current_exception());
Expand Down
22 changes: 7 additions & 15 deletions include/cxxdes/core/impl/coroutine_data.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,18 @@ struct coroutine_data: memory::reference_counted_base<coroutine_data> {
return env_ != nullptr;
}

void stop() {
stopped_ = true;
}

[[nodiscard]]
bool stopped() {
return stopped_;
void destroy() {
complete_ = true;
while (!call_stack_.empty()) {
call_stack_.back().destroy();
call_stack_.pop_back();
}
}

virtual ~coroutine_data() = default;

protected:
// protected, so cannot be captured by user
struct stopped_exception: std::exception {
const char *what() const noexcept override {
return "stopped";
}
};

template <awaitable A>
friend struct awaitable_wrapper;

Expand Down Expand Up @@ -146,7 +139,6 @@ protected:
time_integral latency_ = 0;
memory::ptr<coroutine_data> parent_;
bool complete_ = false;
bool stopped_ = false;
};


Expand Down
5 changes: 1 addition & 4 deletions include/cxxdes/core/impl/environment.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ struct environment {
tkn->handler->invoke(tkn);
}
catch (...) {
reset();
std::rethrow_exception(std::current_exception());
}
}
Expand All @@ -89,7 +88,6 @@ struct environment {
current_coroutine_ = nullptr;
}
else if (tkn->eptr) {
reset();
std::rethrow_exception(tkn->eptr);
}

Expand All @@ -107,8 +105,7 @@ struct environment {

for (auto coroutine: coroutines) {
if (!coroutine->complete()) {
coroutine->stop();
coroutine->resume();
coroutine->destroy();
}
}

Expand Down

0 comments on commit 92e3b34

Please sign in to comment.