Update nest-asyncio/README.md
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
```python
|
||||
def sync(obj):
|
||||
import asyncio, nest_asyncio; nest_asyncio.apply()
|
||||
if asyncio.iscoroutine(obj): return asyncio.run(obj)
|
||||
if asyncio.iscoroutinefunction(func := obj):
|
||||
return lambda *args, **kwargs: sync(func(*args, **kwargs))
|
||||
for attr in dir(obj):
|
||||
if asyncio.iscoroutinefunction(method := getattr(obj, attr)):
|
||||
setattr(obj, attr, sync(method))
|
||||
return obj
|
||||
async def foo(): return 42
|
||||
sync(foo()), sync(foo)()
|
||||
```
|
||||
|
||||
```python
|
||||
def sync(coro):
|
||||
import asyncio, functools
|
||||
|
||||
Reference in New Issue
Block a user