Async python for Event-Driven applications
Project description
AsyncED
Async python for Event-Driven applications
Installation
pip install asynced
High-level API
Coming soon...
Low-level API
Promise
Inspired by (but not a clone of) Javascript promises, asynced.Promise
is a
thin wrapper around any coroutine.
Like asyncio.Task
, when a promise is created, the wrapped coroutine will run
in the background, and can be awaited to get the result or exception. In
addition, a Promise
can be "chained" with sync or async functions, producing
another Promise
.
Example:
import asyncio
from asynced import Promise
async def formulate_ultimate_question() -> str:
await asyncio.sleep(0.25)
return (
'What is The Answer to the Ultimate Question of Life, the Universe, '
'and Everything?'
)
async def compute_answer(question: str):
await asyncio.sleep(0.75)
return (len(question) >> 1) + 1
async def amain():
answer = await Promise(formulate_ultimate_question()).then(compute_answer)
print(answer)
asyncio.run(amain())
Perpetual
Where asyncio futures are the bridge between low-level events and a coroutines, perpetuals are the bridge between event streams and async iterators.
In it's essence, a perpetual is an asyncio.Future that can have its result (or exception) set multiple times, at least until it is stopped. Besides a perpetual being awaitable just like a future, it is an async iterator as well.
ensure_future
Wrap an async iterable in a perpetual, and automatically starts iterating.
See perpetual_drumkit.py for an example.
~
More docs and examples coming soon...
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file asynced-0.2.1.tar.gz
.
File metadata
- Download URL: asynced-0.2.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.3 Linux/5.13.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 750cf9be34a0ba8eca5080cd6c2db8ab0eb56db61d08abf00041a145a3fb7cac |
|
MD5 | 288ab8929975c42791b082c276ab8399 |
|
BLAKE2b-256 | 3e5eb264bb247662dc16453b93831b130a98cef0b7f58bf756a5941d14d48310 |
File details
Details for the file asynced-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: asynced-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.3 Linux/5.13.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ec5834a48b91d2ddad1f30ae182be4f3f31c6b67faaefdbbca9d5d8f98d8725 |
|
MD5 | 5a969173cfaac2010f1fa72cd0dd27e5 |
|
BLAKE2b-256 | 585b3b5814e740beb7b709998a3f8aad3127cbed14ee4a9456170a0390bb8a3d |