Generators and asyncio aren't idiomatic in clojure. #1223
Closed
amano-kenji
started this conversation in
Ideas
Replies: 1 comment
-
I'm promoting this discussion to issues. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Generator
lazy-seq
creates ISeqable which is Iterable. A generator is also Iterable.lazy-seq
is a traditional solution that has worked well. The following generator is somehow redundant.A lazy sequence can do the same job and be passed to any place where a python generator or a python iterator is expected if a lazy sequence is actually collections.abc.Iterable.
I think basilisp should eliminate
yield
.Asyncio
The whole async API is criticized by some python programmers. Gevent does the job by monkey-patching blocking I/O operations and running them in its own green threads. One can get a lazy sequence out of a green thread.
If you don't want to monkey-patch blocking I/O operations, you can also use a green thread library that offloads blocking I/O operations to a thread pool. Unbuffered channels can communicate between threads. Promesa does something similar on JVM. On javascript platforms, promesa doesn't have a thread pool because every I/O operation is non-blocking.
With a thread pool and unbuffered channels, an async value or an async iterator can be converted to synchronous constructs.
I'm just sketching a broad idea. Specific details will have to be fleshed out later.
Instead of supporting async, basilisp programmers can utilize green thread libraries.
Update: core.async seems to be a green thread library, and promesa's core.async implementation seems great.
(basilisp.core.async.interop/async-iterator)
and(basilisp.core.async.interop/coroutine)
can convert async iterators and coroutines to channels with a thread pool and unbuffered channels.Beta Was this translation helpful? Give feedback.
All reactions