Convert async functions to sync and vice versa.
Project description
Desync
Simple conversions between synchronous and asynchronous functions and function
calls. You can use it to wait (really block) for asynchronous function results
with sync or create synchronous versions with synced:
# Assume async_func is asynchronous.
async_func: Callable[..., Awaitable[T]]
# Call async_func and wait for its result synchronously:
result: T = sync(async_func, *args, **kwargs)
# Create a version which is synchronous without calling it:
desynced_func: Callable[..., T] = synced(async_func)
You can also wait for synchronous functions via desync or create asynchronous
versions with desynced:
# Assume sync_func is synchronous.
func: Callable[..., T]
# Call sync_func and wait for its result in an asynchronous context:
awaitable: Awaitable[T] = desync(sync_func, *args, **kwargs)
result: T = await awaitable
# Create a version which is asynchronous without calling it:
descyned_func: Callable[..., Awaitable[T]] = desynced(func)
Desynced functions run in parallel (as far as python can run in parallel).
def wait_some():
time.sleep(1)
return 1
# This should take approx. 1 second:
assert 10 == sum(
await asyncio.gather(*(
desync(wait_some) for i in range(10)
))
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydesync-0.1.3.tar.gz.
File metadata
- Download URL: pydesync-0.1.3.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e78b4e4d146a123b224bba5562d4fbc1d749eea5b0ad4764ab8f39d2b1bc23c
|
|
| MD5 |
68fcb80e019d093f4d7bab2954b6eb8b
|
|
| BLAKE2b-256 |
4396fa4e7d3f63bc018c03e8da6ed425c87c6b945f0e909b4c02ab8f428eddc5
|
File details
Details for the file pydesync-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pydesync-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e2a43e28aba73a9c6b96a96157a884d7b05c26c256a660ac3e247db5af98e5c
|
|
| MD5 |
d2f04aad7b977a3bc136920f6b692e9c
|
|
| BLAKE2b-256 |
11b6fe352e3165ba95dde68bef06465275622afba7ef7d407cd2ec3e948d56ff
|