Skip to content

Instantly share code, notes, and snippets.

@njsmith
Created July 27, 2018 05:08
Show Gist options
  • Select an option

  • Save njsmith/a9f9d57b5665d0b49ae818e30a0a2863 to your computer and use it in GitHub Desktop.

Select an option

Save njsmith/a9f9d57b5665d0b49ae818e30a0a2863 to your computer and use it in GitHub Desktop.
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