-
-
Notifications
You must be signed in to change notification settings - Fork 67
Early co_returns do not resume the caller #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Indeed, this should work as you described. Thanks for the nice reproducer. |
Is there anything I could help with debugging? I'm just starting out with co-routines, so I'm still a bit lost in all the template magic, but maybe you have an idea/hint what may go wrong here? |
Hi, sorry for not fixing this yet, I'm a bit busy with work :( The problem is that the fact that the coroutine has finished synchronously doesn't propagate to the Task<> that is returned to the caller, so when you The fix here is to check for the state of the Task before suspending it... |
Hi, no big deal. I now tried to fix this myself, but I can't get it to work 100%:
Any ideas? |
Your investigation is correct and you are heading in the right direction.There are two cases that main need to be handled:
I think the right approach that I'm pursuing now, is to indeed destroy the coroutine from |
Co-routines returning immediately with co_return would have an invalid result, because the co-routine handle was destroyed before the caller had a chance to get the result. We do have to make sure to still destroy co-routines in final-suspend, if nobody is awaiting the result (e.g. when called from Qt's event loop). Fixes: qcoro#24
Co-routines returning immediately with co_return would have an invalid result, because the co-routine handle was destroyed before the caller had a chance to get the result. We do have to make sure to still destroy co-routines in final-suspend, if nobody is awaiting the result (e.g. when called from Qt's event loop). Fixes: qcoro#24
Fix issue #24: Early co_returns do not resume the caller
Maybe I'm not understanding correctly how coroutines work, but I think the following example should work for both cases: returning early and awaited from
testReturn
.What I'm seeing (gcc 11 and MSVC 2019) is that
testImmediate
just hangs and never returns from itsco_await
Output:
The text was updated successfully, but these errors were encountered: