My first coroutine—Kirit Sælensminde

Save to:
Instapaper Pocket Readability

What's the point of coroutines?

My first coroutine

by Kirit Sælensminde

From the article:

There are more and more examples coming out of how to convert things like the use of futures into coroutines, and you may be forgiven for thinking that there is also some magic that happens in boost::future or std::future that lets this work, but that's not the case.

In C++ a coroutine is any function that contains one of the coroutine keywords in its body, that is any of co_return, co_yield or co_await.

What we're going to do is to write a very basic mechanism that allows us to use co_return to return a value from a coroutine. Coroutines are really a generalisation of a function call, and what this is going to allow us to do is to treat a coroutine as a function call. If we can't do this then we don't stand much chance of doing anything more interesting with them, but it will give us a good starter on how the machinery works...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.