Forechan
go style asyncio channels.
Fully Typed with Generics, mypy ready.
Inspired by core.async from clojure.
Examples
Send & Recv
ch = chan(int) # Chan[int]
await (ch << 2) # or use `await ch.send(x)`
two = await ([] << ch) # or use `await ch.recv()`
assert two == 2
# `ch.close()` is idempotent
await ch.close()
Basic
if ch:
# if `Chan[T]` is open
len(ch) # How many items are in `ch`
async with ch:
# close `ch` after exiting lexical-scope
async for item in ch:
# use `ch` as AsyncIterator
Select
async for ch, item in select(ch1, ch2, ch3, ...):
if ch == ch1:
...
elif ch == ch2:
...
elif ch == ch3:
...
Wait Group
wg = wait_group()
for _ in range(5):
async def cont() -> None:
with wg:
# do some work
create_task(cont())
# will wait for all work to be completed
await wg.wait()
Synchronous
head = ch.try_peek() # can throw `ChanEmpty`
(ch < 2) # or use `ch.try_send(2)` , can throw `ChanFull`
two = ([] < ch) # or use `ch.try_recv()` , can throw `ChanEmpty`
assert two == 2
Go -> Python
The following are roughly equivalent
func fn() {
// do things here
}
go fn()
When GOMAXPROCS=1
async def fn() -> None:
# do things here
create_task(fn())
Common Concurrency Patterns
Consumer
async def consumer() -> None:
async for item in ch:
# do something with `item`, until `ch` is closed
Producer
def producer() -> Chan[int]:
ch = chan(int)
async def cont() -> None:
# auto close `ch` when done
async with ch:
while ...:
# send result `item` to downstream `ch`
await (ch << item)
create_task(cont())
return ch
Series of Tubes
Metadata
Release files for forechan 0.2.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| forechan-0.2.10.tar.gz | 9.2 kB | Without provenance | Details for forechan-0.2.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| forechan-0.2.10-py3-none-any.whl | Python 3 | none | any | Details for forechan-0.2.10-py3-none-any.whl |
Total release size: 21.2 kB
Release files / forechan-0.2.10.tar.gz
| Download URL | forechan-0.2.10.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8274b46e92b6f5bb0d87e0223edf58bd9a901c96cb98c922ec7eeee0af7615b7
|
|
BLAKE2b-256 checksum How to use checksums |
21e899bd2dc81d01587552ee7a81f896edaf5ae6d0c44a6085ef4c1b841ae03b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / forechan-0.2.10-py3-none-any.whl
| Download URL | forechan-0.2.10-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
824dc45021a8ff00cf554a97cdb12bef8665d75c43b74b990b27d9e2f10ce897
|
|
BLAKE2b-256 checksum How to use checksums |
eee5a4bbb6793382618ffcfefb132268525d698fd7deb58c8d8f33491044257e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Security for forechan 0.2.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.