I've created a small python2.x compatible framework that implements coroutines using generators that yield Futures. I will post the code shortly. I'd like to use this to avoid using asynchronous callbacks when possible.
Patch posted for review: https://github.com/gentoo/portage/pull/331 https://archives.gentoo.org/gentoo-portage-dev/message/504c701fd84f8c86db4c449e3b18a569
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/proj/portage.git/commit/?id=edba848a013e1797faeacc1911a5e6571fca3ca7 commit edba848a013e1797faeacc1911a5e6571fca3ca7 Author: Zac Medico <zmedico@gentoo.org> AuthorDate: 2018-07-05 04:44:42 +0000 Commit: Zac Medico <zmedico@gentoo.org> CommitDate: 2018-07-11 07:40:59 +0000 Add python2 compatible coroutine support (bug 660426) For readability, it's desirable to make asynchronous code use coroutines to avoid callbacks when possible. For python2 compatibility, generators that yield Futures can be used to implement coroutines. Add a compat_coroutine module which provides a @coroutine decorator and a coroutine_return function that can be used to return a value from a generator. The decorated function returns a Future which is done when the generator is exhausted. Usage is very similar to asyncio coroutine usage in python3.4 (see unit tests). Bug: https://bugs.gentoo.org/660426 .../tests/util/futures/test_compat_coroutine.py | 159 +++++++++++++++++++++ pym/portage/util/futures/compat_coroutine.py | 112 +++++++++++++++ 2 files changed, 271 insertions(+)