Commit dfbd8f84 authored by Tom Niget's avatar Tom Niget

Add initial support for generators with parameters

parent 960389fb
...@@ -22,7 +22,7 @@ class Generator ...@@ -22,7 +22,7 @@ class Generator
Promise() = default; Promise() = default;
std::suspend_always initial_suspend() { return {}; } std::suspend_always initial_suspend() { return {}; }
std::suspend_always final_suspend() noexcept { return {}; } std::suspend_always final_suspend() noexcept { final = true; return {}; }
void unhandled_exception() { void unhandled_exception() {
std::rethrow_exception(std::move(std::current_exception())); std::rethrow_exception(std::move(std::current_exception()));
} }
...@@ -47,11 +47,13 @@ class Generator ...@@ -47,11 +47,13 @@ class Generator
} }
bool finished() { bool finished() {
return !value.has_value(); //return !value.has_value();
return final;
} }
private: private:
value_type value{}; value_type value{};
bool final = false;
}; };
public: public:
...@@ -68,7 +70,9 @@ public: ...@@ -68,7 +70,9 @@ public:
Promise::value_type next() { Promise::value_type next() {
if (handle) { if (handle) {
if (!handle.promise().finished()) {
handle.resume(); handle.resume();
}
return handle.promise().get_value(); return handle.promise().get_value();
} }
else { else {
...@@ -135,7 +139,7 @@ public: ...@@ -135,7 +139,7 @@ public:
} }
std::optional<value_type> py_next() { std::optional<value_type> py_next() {
return *begin(); return next();
} }
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment