Created
July 27, 2018 05:08
-
-
Save njsmith/a9f9d57b5665d0b49ae818e30a0a2863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import types | |
| class FakeFuture: | |
| _asyncio_future_blocking = True | |
| @property | |
| def _loop(self): | |
| import asyncio | |
| return asyncio.get_event_loop() | |
| def add_done_callback(self, fn, **kwargs): | |
| # **kwargs to carry context=, on asyncio's that support it | |
| self._loop.call_soon(fn, self, **kwargs) | |
| def result(self): | |
| pass | |
| LIBRARY_QUERY_SENTINEL = FakeFuture() | |
| @types.coroutine | |
| def current_async_library(): | |
| value = yield LIBRARY_QUERY_SENTINEL | |
| if value is None: | |
| return "asyncio" | |
| else: | |
| return value | |
| ################################################################ | |
| import asyncio | |
| async def main(): | |
| print(await current_async_library()) | |
| loop = asyncio.get_event_loop() | |
| loop.run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment