basilisp icon indicating copy to clipboard operation
basilisp copied to clipboard

`basilisp.core.async` namespace

Open chrisrink10 opened this issue 7 years ago • 5 comments

chrisrink10 avatar Sep 11 '18 13:09 chrisrink10

The functionality of core.async depends primarily on the channel primitive. The package aiochan implements the channel primitive using Python's builtin async/await functionality. This would be a super rad enhancement.

chrisrink10 avatar Mar 15 '20 03:03 chrisrink10

Hi,

maybe this will be helpful: I've done ~as you suggested, using aiochan + async/await to have something /like/ core.async in my own code

a significant consideration/design element is:

  • in python, running an event loop blocks a thread, so only one can be "live" per thread
  • in clojure, async go blocks use a fixed thread-pool and so operate independently, "go" is shipping stuff to another thread
  • aiochan is event-loop async/await oriented not thread-oriented
  • if we use pure event-loop implementation, it looks more like cljs where everything is sharing one thread
    • but in order to run an event loop we need to block a thread
    • threads can't (simply) share event loops
  • what I'm currently doing is defining an event-loop/thread dedicated on app startup, putting it in a top-level var and passing it around, then using run_coroutine_threadsafe (inside my go macro) to push async things into my dedicated event-loop-thread

This was fairly simple to implement but isn't allowing parallelism, unlike clojure go-blocks do by default, and somehow seems unclojuric, maybe better to run a thread per go block a-la clojure, or maybe given GIL a process. THen would need to work out how to create a thread/process-safe channel implementation though, or hack aiochan.

FalseProtagonist avatar Dec 11 '24 13:12 FalseProtagonist