3 ms·
I'm a bit surprised that there didn't appear to be any mention of Clojure's built-in concurrency support outside of basic immutability. core.async gives a nice
by tombert 8y ago
I'm a bit surprised that there didn't appear to be any mention of Clojure's built-in concurrency support outside of basic immutability. core.async gives a nice channel-based system, agents give an actor-ish system, and STM/atoms let you mutate the variable safely, without having to manually work with locks.
This is definitely a good high-level article, just something I was surprised by, since core.async is what drove me (and several other people I know) to start using Clojure.
EDIT: Just a note that I know core.async isn't built in, that was a mistake. It is a first-party library, however.
- burittoTTY 8y agoIndeed, Clojure also has unfettered access to Java's concurrency primitives.
- throwaway2-32 8y ago52 major open issues, 2 critical issues, and 38 others major issues list memory leaks. https://dev.clojure.org/jira/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+ASYNC+AND+resolution+%3D+Unresolved+AND+priority+%3D+Major+ORDER+BY+key+DESC&mode=hide https://dev.clojure.org/jira/secure/IssueNavigator.jspa?rese... first-party?
- bgorman 8y agoCore async is maintained by Cognitect (maintainers of Clojure). It is very commonly used, and it has been upgraded to mesh well with the rest of the language over time (namely support for transducers).
- tombert 8y agoI don't really know what that has to do with anything; every piece of software has bugs. I haven't really encountered any issues with core.async yet. I suspect you could find similar bugs in nearly any popular concurrency library. By first-party, I mean it seems to be officially part of the Clojure ecosystem, the docs are hosted on the main site: https://clojure.github.io/core.async/ https://clojure.github.io/core.async/
- christophilus 8y agoEvery commonly used project has a ton of open issues. Look at React, VS Code, Docker, etc It doesn’t mean it’s not production ready.
- stingraycharles 8y agoIt’s also worth noting that almost nobody uses agents or STM (except for some highly specific use cases, but I’ve never seen them in years), and core.async is a library, not a part of Clojure (which is a good thing, because it promotes choice and keeps the language small).
- jwr 8y agoI did use agents in the past, but stopped since core.async became available: it addresses the use cases for agents in a much more flexible way. Also, I found that handling errors in agents is difficult. As for the general use case, atoms and core.async are great tools, and I haven't needed to use refs (aka the STM) for years.
- tombert 8y agoDon't the core.async go-blocks have issues if you need to block on IO heavy stuff, as in the thread-pool will be blocked until the side-effects are done? Agents don't have that problem, at least I don't think they do.
- lastofus 8y agoI believe all I/O is blocking unless you use something that wraps NIO. This is definitely true for core.async threads, but I'm not sure why it would any different for agents. This is also a bit of a departure for people coming from Go or Erlang/Elixir.
- tombert 8y agoAgents are run in a separate pool, and no one agent is processing at a time, so I suppose they're not "parallel", but concurrent still. I think the agents are preemptive, but I'm not 100% sure on that.
- lastofus 8y agoI found this comment enlightening: https://clojuredocs.org/clojure.core/send-off#example-59347211e4b06e730307db22 https://clojuredocs.org/clojure.core/send-off#example-593472... It seems like there are a lot of parallels between agents and core.async. Agents, like go blocks, run in a thread pool. Any blocking IO should be pushed off to a separate thread outside of the thread pool. In the case of agents, there is (send-off). In the case of core.async, there is (thread)
- jwr 8y agoYes, core.async should definitely be mentioned. It's also much more than a nice channel-based system, but you have to dive in to appreciate how good it is. For example, you have to write real systems to appreciate the fact that core.async channels can be used both from "go-threads" and real threads. That's really useful when your async work involves both quickly sending responses to clients (where lightweight go-threads shine) and doing heavy I/O for database updates (where you want a thread to pick up the work). You use the same channels for all types of work, which is really neat.
- simplect 8y agoIt was not built-in because it WAS possible, unlike other languages. So I think the argument in this specific case is mute.
- leshow 8y agoSTM in Haskell is really nice to use also.