Skip to content

co_await vs QCoro::waitFor()? #210

Closed Answered by danvratil
MicahSpikah asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

regarding QCoro::waitFor(), there's one thing to consider: QCoro::waitFor() internally runs a nested QEventLoop - and it's always better to avoid nested QEventLoops due to potential re-entrancy issues. The construction of nested QEventLoop and the handling of things adds a small overhead, so it would make coroutines slightly more expensive.

But trhanks to the nature of QCoro's coroutines, you should be able to do

connect( &timer, &QTimer::timeout, this, &ThisClass::request_data_from_serial);

QCoro::Task is an eager coroutine (it starts automatically when called, it doesn't need to be co_awaited) and is designed specifically to run to its completion even when not co_awaited.

QCoro::wai…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MicahSpikah
Comment options

Answer selected by MicahSpikah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants